changeset 12458:d601e4bba306

7160380: Sync JDK8 with JAXP 1.4.5 Summary: bring JDK8 up to date to what we have in 7u4 Reviewed-by: lancea, mullan
author joehw
date Tue, 17 Apr 2012 11:17:59 -0700
parents c348e06f0e82
children dffc89f36a91
files jaxp/src/com/sun/org/apache/xalan/internal/XalanConstants.java jaxp/src/com/sun/org/apache/xalan/internal/lib/ExsltDatetime.java jaxp/src/com/sun/org/apache/xalan/internal/lib/ExsltMath.java jaxp/src/com/sun/org/apache/xalan/internal/lib/Extensions.java jaxp/src/com/sun/org/apache/xalan/internal/lib/ObjectFactory.java jaxp/src/com/sun/org/apache/xalan/internal/lib/SecuritySupport.java jaxp/src/com/sun/org/apache/xalan/internal/lib/SecuritySupport12.java jaxp/src/com/sun/org/apache/xalan/internal/utils/ConfigurationError.java jaxp/src/com/sun/org/apache/xalan/internal/utils/FactoryImpl.java jaxp/src/com/sun/org/apache/xalan/internal/utils/ObjectFactory.java jaxp/src/com/sun/org/apache/xalan/internal/utils/SecuritySupport.java jaxp/src/com/sun/org/apache/xalan/internal/xslt/EnvironmentCheck.java jaxp/src/com/sun/org/apache/xalan/internal/xslt/ObjectFactory.java jaxp/src/com/sun/org/apache/xalan/internal/xslt/Process.java jaxp/src/com/sun/org/apache/xalan/internal/xslt/SecuritySupport.java jaxp/src/com/sun/org/apache/xalan/internal/xslt/SecuritySupport12.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/Translet.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/cmdline/Compile.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/cmdline/ObjectFactory.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/cmdline/SecuritySupport.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/cmdline/SecuritySupport12.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/cmdline/Transform.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/AbsoluteLocationPath.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/AbsolutePathPattern.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/AttributeSet.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Copy.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/FilterExpr.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/FilterParentPath.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/FilteredAbsoluteLocationPath.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/FunctionAvailableCall.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/FunctionCall.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Key.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Message.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Mode.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Number.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/ObjectFactory.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/ParameterRef.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/ParentLocationPath.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/ParentPattern.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Parser.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Predicate.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/ProcessingInstruction.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/SecuritySupport.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/SecuritySupport12.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Sort.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Step.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/StepPattern.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Stylesheet.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/SymbolTable.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/SyntaxTreeNode.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/TestSeq.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Variable.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/VariableBase.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/VariableRef.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Whitespace.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/XSLTC.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/XslAttribute.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/XslElement.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/util/ClassGenerator.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/util/ErrorMessages.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/util/ErrorMsg.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/util/InternalError.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/util/MarkerInstruction.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/util/MethodGenerator.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/util/ObjectFactory.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/util/ObjectType.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/util/OutlineableChunkEnd.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/util/OutlineableChunkStart.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/util/RealType.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/util/ResultTreeType.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/util/SecuritySupport.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/util/SecuritySupport12.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/dom/ArrayNodeListIterator.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/dom/DupFilterIterator.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/dom/NodeSortRecord.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/dom/NodeSortRecordFactory.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/dom/ObjectFactory.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/dom/SecuritySupport.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/dom/SecuritySupport12.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/dom/XSLTCDTMManager.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/runtime/AbstractTranslet.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/runtime/BasisLibrary.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/runtime/Hashtable.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/runtime/InternalRuntimeError.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/runtime/ObjectFactory.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/runtime/SecuritySupport.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/runtime/SecuritySupport12.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/runtime/output/TransletOutputHandlerFactory.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/trax/ObjectFactory.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/trax/SAX2DOM.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/trax/SecuritySupport.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/trax/SecuritySupport12.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/trax/SmartTransformerFactoryImpl.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/trax/TemplatesHandlerImpl.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/trax/TemplatesImpl.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/trax/TrAXFilter.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerFactoryImpl.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/trax/TransformerImpl.java jaxp/src/com/sun/org/apache/xalan/internal/xsltc/trax/Util.java jaxp/src/com/sun/org/apache/xerces/internal/dom/CoreDOMImplementationImpl.java jaxp/src/com/sun/org/apache/xerces/internal/dom/CoreDocumentImpl.java jaxp/src/com/sun/org/apache/xerces/internal/dom/DOMConfigurationImpl.java jaxp/src/com/sun/org/apache/xerces/internal/dom/ObjectFactory.java jaxp/src/com/sun/org/apache/xerces/internal/dom/SecuritySupport.java jaxp/src/com/sun/org/apache/xerces/internal/impl/Constants.java jaxp/src/com/sun/org/apache/xerces/internal/impl/XMLDocumentFragmentScannerImpl.java jaxp/src/com/sun/org/apache/xerces/internal/impl/XMLEntityManager.java jaxp/src/com/sun/org/apache/xerces/internal/impl/XMLEntityScanner.java jaxp/src/com/sun/org/apache/xerces/internal/impl/XMLStreamReaderImpl.java jaxp/src/com/sun/org/apache/xerces/internal/impl/dv/DTDDVFactory.java jaxp/src/com/sun/org/apache/xerces/internal/impl/dv/ObjectFactory.java jaxp/src/com/sun/org/apache/xerces/internal/impl/dv/SchemaDVFactory.java jaxp/src/com/sun/org/apache/xerces/internal/impl/dv/SecuritySupport.java jaxp/src/com/sun/org/apache/xerces/internal/impl/msg/XMLSchemaMessages.properties jaxp/src/com/sun/org/apache/xerces/internal/impl/xpath/regex/ParserForXMLSchema.java jaxp/src/com/sun/org/apache/xerces/internal/impl/xs/XMLSchemaLoader.java jaxp/src/com/sun/org/apache/xerces/internal/impl/xs/XMLSchemaValidator.java jaxp/src/com/sun/org/apache/xerces/internal/impl/xs/identity/Field.java jaxp/src/com/sun/org/apache/xerces/internal/jaxp/datatype/XMLGregorianCalendarImpl.java jaxp/src/com/sun/org/apache/xerces/internal/jaxp/validation/DOMValidatorHelper.java jaxp/src/com/sun/org/apache/xerces/internal/jaxp/validation/StAXValidatorHelper.java jaxp/src/com/sun/org/apache/xerces/internal/jaxp/validation/StreamValidatorHelper.java jaxp/src/com/sun/org/apache/xerces/internal/jaxp/validation/ValidatorHandlerImpl.java jaxp/src/com/sun/org/apache/xerces/internal/jaxp/validation/XMLSchemaFactory.java jaxp/src/com/sun/org/apache/xerces/internal/parsers/AbstractDOMParser.java jaxp/src/com/sun/org/apache/xerces/internal/parsers/DOMParser.java jaxp/src/com/sun/org/apache/xerces/internal/parsers/DOMParserImpl.java jaxp/src/com/sun/org/apache/xerces/internal/parsers/ObjectFactory.java jaxp/src/com/sun/org/apache/xerces/internal/parsers/SAXParser.java jaxp/src/com/sun/org/apache/xerces/internal/parsers/SecuritySupport.java jaxp/src/com/sun/org/apache/xerces/internal/parsers/XMLDocumentParser.java jaxp/src/com/sun/org/apache/xerces/internal/parsers/XMLGrammarParser.java jaxp/src/com/sun/org/apache/xerces/internal/parsers/XMLGrammarPreparser.java jaxp/src/com/sun/org/apache/xerces/internal/util/ParserConfigurationSettings.java jaxp/src/com/sun/org/apache/xerces/internal/utils/ConfigurationError.java jaxp/src/com/sun/org/apache/xerces/internal/utils/ObjectFactory.java jaxp/src/com/sun/org/apache/xerces/internal/utils/SecuritySupport.java jaxp/src/com/sun/org/apache/xerces/internal/xinclude/XIncludeHandler.java jaxp/src/com/sun/org/apache/xml/internal/dtm/DTMManager.java jaxp/src/com/sun/org/apache/xml/internal/dtm/ObjectFactory.java jaxp/src/com/sun/org/apache/xml/internal/dtm/SecuritySupport.java jaxp/src/com/sun/org/apache/xml/internal/dtm/SecuritySupport12.java jaxp/src/com/sun/org/apache/xml/internal/dtm/ref/DTMDefaultBase.java jaxp/src/com/sun/org/apache/xml/internal/dtm/ref/DTMManagerDefault.java jaxp/src/com/sun/org/apache/xml/internal/dtm/ref/IncrementalSAXSource_Xerces.java jaxp/src/com/sun/org/apache/xml/internal/dtm/ref/ObjectFactory.java jaxp/src/com/sun/org/apache/xml/internal/dtm/ref/SecuritySupport.java jaxp/src/com/sun/org/apache/xml/internal/dtm/ref/SecuritySupport12.java jaxp/src/com/sun/org/apache/xml/internal/dtm/ref/dom2dtm/DOM2DTM.java jaxp/src/com/sun/org/apache/xml/internal/resolver/Catalog.java jaxp/src/com/sun/org/apache/xml/internal/resolver/CatalogManager.java jaxp/src/com/sun/org/apache/xml/internal/resolver/Resolver.java jaxp/src/com/sun/org/apache/xml/internal/resolver/tools/CatalogResolver.java jaxp/src/com/sun/org/apache/xml/internal/resolver/tools/ResolvingParser.java jaxp/src/com/sun/org/apache/xml/internal/resolver/tools/ResolvingXMLFilter.java jaxp/src/com/sun/org/apache/xml/internal/resolver/tools/ResolvingXMLReader.java jaxp/src/com/sun/org/apache/xml/internal/serialize/SerializerFactory.java jaxp/src/com/sun/org/apache/xml/internal/serializer/CharInfo.java jaxp/src/com/sun/org/apache/xml/internal/serializer/EmptySerializer.java jaxp/src/com/sun/org/apache/xml/internal/serializer/Encodings.java jaxp/src/com/sun/org/apache/xml/internal/serializer/ObjectFactory.java jaxp/src/com/sun/org/apache/xml/internal/serializer/OutputPropertiesFactory.java jaxp/src/com/sun/org/apache/xml/internal/serializer/SecuritySupport.java jaxp/src/com/sun/org/apache/xml/internal/serializer/SecuritySupport12.java jaxp/src/com/sun/org/apache/xml/internal/serializer/SerializationHandler.java jaxp/src/com/sun/org/apache/xml/internal/serializer/SerializerBase.java jaxp/src/com/sun/org/apache/xml/internal/serializer/SerializerFactory.java jaxp/src/com/sun/org/apache/xml/internal/serializer/ToHTMLSAXHandler.java jaxp/src/com/sun/org/apache/xml/internal/serializer/ToHTMLStream.java jaxp/src/com/sun/org/apache/xml/internal/serializer/ToStream.java jaxp/src/com/sun/org/apache/xml/internal/serializer/ToXMLSAXHandler.java jaxp/src/com/sun/org/apache/xml/internal/serializer/ToXMLStream.java jaxp/src/com/sun/org/apache/xml/internal/serializer/WriterToUTF8Buffered.java jaxp/src/com/sun/org/apache/xml/internal/serializer/utils/URI.java jaxp/src/com/sun/org/apache/xml/internal/utils/ObjectFactory.java jaxp/src/com/sun/org/apache/xml/internal/utils/ObjectPool.java jaxp/src/com/sun/org/apache/xml/internal/utils/SecuritySupport.java jaxp/src/com/sun/org/apache/xml/internal/utils/SecuritySupport12.java jaxp/src/com/sun/org/apache/xml/internal/utils/TreeWalker.java jaxp/src/com/sun/org/apache/xml/internal/utils/URI.java jaxp/src/com/sun/org/apache/xml/internal/utils/XMLReaderManager.java jaxp/src/com/sun/org/apache/xml/internal/utils/XMLString.java jaxp/src/com/sun/org/apache/xml/internal/utils/XMLStringDefault.java jaxp/src/com/sun/org/apache/xpath/internal/XPathContext.java jaxp/src/com/sun/org/apache/xpath/internal/axes/AxesWalker.java jaxp/src/com/sun/org/apache/xpath/internal/axes/BasicTestIterator.java jaxp/src/com/sun/org/apache/xpath/internal/axes/DescendantIterator.java jaxp/src/com/sun/org/apache/xpath/internal/axes/IteratorPool.java jaxp/src/com/sun/org/apache/xpath/internal/axes/MatchPatternIterator.java jaxp/src/com/sun/org/apache/xpath/internal/axes/OneStepIterator.java jaxp/src/com/sun/org/apache/xpath/internal/axes/OneStepIteratorForward.java jaxp/src/com/sun/org/apache/xpath/internal/axes/UnionPathIterator.java jaxp/src/com/sun/org/apache/xpath/internal/axes/WalkerFactory.java jaxp/src/com/sun/org/apache/xpath/internal/axes/WalkingIterator.java jaxp/src/com/sun/org/apache/xpath/internal/compiler/FuncLoader.java jaxp/src/com/sun/org/apache/xpath/internal/compiler/ObjectFactory.java jaxp/src/com/sun/org/apache/xpath/internal/compiler/OpMap.java jaxp/src/com/sun/org/apache/xpath/internal/compiler/SecuritySupport.java jaxp/src/com/sun/org/apache/xpath/internal/compiler/SecuritySupport12.java jaxp/src/com/sun/org/apache/xpath/internal/functions/FuncSystemProperty.java jaxp/src/com/sun/org/apache/xpath/internal/functions/ObjectFactory.java jaxp/src/com/sun/org/apache/xpath/internal/functions/SecuritySupport.java jaxp/src/com/sun/org/apache/xpath/internal/functions/SecuritySupport12.java jaxp/src/com/sun/org/apache/xpath/internal/jaxp/XPathExpressionImpl.java jaxp/src/com/sun/org/apache/xpath/internal/jaxp/XPathFactoryImpl.java jaxp/src/com/sun/org/apache/xpath/internal/jaxp/XPathImpl.java jaxp/src/com/sun/org/apache/xpath/internal/objects/XString.java jaxp/src/com/sun/org/apache/xpath/internal/objects/XStringForFSB.java jaxp/src/com/sun/org/apache/xpath/internal/patterns/StepPattern.java jaxp/src/com/sun/xml/internal/stream/XMLEntityStorage.java jaxp/src/com/sun/xml/internal/stream/writers/XMLStreamWriterImpl.java jaxp/src/javax/xml/datatype/FactoryFinder.java jaxp/src/javax/xml/parsers/FactoryFinder.java jaxp/src/javax/xml/stream/FactoryFinder.java jaxp/src/javax/xml/transform/FactoryFinder.java jaxp/src/javax/xml/validation/SchemaFactoryFinder.java jaxp/src/javax/xml/xpath/XPathFactoryFinder.java
diffstat 217 files changed, 6250 insertions(+), 16422 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/XalanConstants.java	Tue Apr 17 11:17:59 2012 -0700
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2011 Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.org.apache.xalan.internal;
+
+import com.sun.org.apache.xerces.internal.impl.*;
+import java.util.Enumeration;
+import java.util.NoSuchElementException;
+
+/**
+ * Commonly used constants.
+ *
+ * @author Huizhe Wang, Oracle
+ *
+ * @version $Id: Constants.java,v 1.14 2011-06-07 04:39:40 joehw Exp $
+ */
+public final class XalanConstants {
+
+    //
+    // Constants
+    //
+    // Oracle Feature:
+        /**
+         * <p>Use Service Mechanism</p>
+         *
+         * <ul>
+         *   <li>
+         *     <code>true</code> instructs the implementation to use service mechanism to find implementation.
+         *     This is the default behavior.
+         *   </li>
+         *   <li>
+         *     <code>false</code> instructs the implementation to skip service mechanism and use the default implementation.
+         *   </li>
+         * </ul>
+         */
+    public static final String ORACLE_FEATURE_SERVICE_MECHANISM = "http://www.oracle.com/feature/use-service-mechanism";
+
+} // class Constants
--- a/jaxp/src/com/sun/org/apache/xalan/internal/lib/ExsltDatetime.java	Thu Apr 12 08:38:26 2012 -0700
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/lib/ExsltDatetime.java	Tue Apr 17 11:17:59 2012 -0700
@@ -97,7 +97,7 @@
         // In a few cases, the time zone may be +/-hh:30.
         int min = offset%(60*60*1000);
         char posneg = hrs < 0? '-': '+';
-        buff.append(posneg + formatDigits(hrs) + ':' + formatDigits(min));
+        buff.append(posneg).append(formatDigits(hrs)).append(':').append(formatDigits(min));
       }
       return buff.toString();
     }
--- a/jaxp/src/com/sun/org/apache/xalan/internal/lib/ExsltMath.java	Thu Apr 12 08:38:26 2012 -0700
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/lib/ExsltMath.java	Tue Apr 17 11:17:59 2012 -0700
@@ -381,7 +381,7 @@
        if (bits <= value.length())
          value = value.substring(0, bits);
 
-       return new Double(value).doubleValue();
+       return Double.parseDouble(value);
      }
      else
        return Double.NaN;
--- a/jaxp/src/com/sun/org/apache/xalan/internal/lib/Extensions.java	Thu Apr 12 08:38:26 2012 -0700
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/lib/Extensions.java	Tue Apr 17 11:17:59 2012 -0700
@@ -35,6 +35,7 @@
 import com.sun.org.apache.xpath.internal.objects.XBoolean;
 import com.sun.org.apache.xpath.internal.objects.XNumber;
 import com.sun.org.apache.xpath.internal.objects.XObject;
+import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
 
 import org.w3c.dom.Document;
 import org.w3c.dom.DocumentFragment;
@@ -363,8 +364,7 @@
     try
     {
       // Use reflection to try to find xml-commons utility 'Which'
-      Class clazz = ObjectFactory.findProviderClass(
-        WHICH_CLASSNAME, ObjectFactory.findClassLoader(), true);
+      Class clazz = ObjectFactory.findProviderClass(WHICH_CLASSNAME, true);
       if (null == clazz)
         return null;
 
--- a/jaxp/src/com/sun/org/apache/xalan/internal/lib/ObjectFactory.java	Thu Apr 12 08:38:26 2012 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,661 +0,0 @@
-/*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
- */
-/*
- * Copyright 2001-2004 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * 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: ObjectFactory.java,v 1.2.4.1 2005/09/15 02:39:54 jeffsuttor Exp $
- */
-
-package com.sun.org.apache.xalan.internal.lib;
-
-import java.io.InputStream;
-import java.io.IOException;
-import java.io.File;
-import java.io.FileInputStream;
-
-import java.util.Properties;
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
-
-/**
- * This class is duplicated for each JAXP subpackage so keep it in sync.
- * It is package private and therefore is not exposed as part of the JAXP
- * API.
- * <p>
- * This code is designed to implement the JAXP 1.1 spec pluggability
- * feature and is designed to run on JDK version 1.1 and
- * later, and to compile on JDK 1.2 and onward.
- * The code also runs both as part of an unbundled jar file and
- * when bundled as part of the JDK.
- * <p>
- * This class was moved from the <code>javax.xml.parsers.ObjectFactory</code>
- * class and modified to be used as a general utility for creating objects
- * dynamically.
- *
- * @version $Id: ObjectFactory.java,v 1.9 2008/04/02 00:40:59 joehw Exp $
- */
-class ObjectFactory {
-
-    //
-    // Constants
-    //
-
-    // name of default properties file to look for in JDK's jre/lib directory
-    private static final String DEFAULT_PROPERTIES_FILENAME =
-                                                     "xalan.properties";
-
-    private static final String SERVICES_PATH = "META-INF/services/";
-
-    /** Set to true for debugging */
-    private static final boolean DEBUG = false;
-
-    /** cache the contents of the xalan.properties file.
-     *  Until an attempt has been made to read this file, this will
-     * be null; if the file does not exist or we encounter some other error
-     * during the read, this will be empty.
-     */
-    private static Properties fXalanProperties = null;
-
-    /***
-     * Cache the time stamp of the xalan.properties file so
-     * that we know if it's been modified and can invalidate
-     * the cache when necessary.
-     */
-    private static long fLastModified = -1;
-
-    //
-    // Public static methods
-    //
-
-    /**
-     * Finds the implementation Class object in the specified order.  The
-     * specified order is the following:
-     * <ol>
-     *  <li>query the system property using <code>System.getProperty</code>
-     *  <li>read <code>META-INF/services/<i>factoryId</i></code> file
-     *  <li>use fallback classname
-     * </ol>
-     *
-     * @return instance of factory, never null
-     *
-     * @param factoryId             Name of the factory to find, same as
-     *                              a property name
-     * @param fallbackClassName     Implementation class name, if nothing else
-     *                              is found.  Use null to mean no fallback.
-     *
-     * @exception ObjectFactory.ConfigurationError
-     */
-    static Object createObject(String factoryId, String fallbackClassName)
-        throws ConfigurationError {
-        return createObject(factoryId, null, fallbackClassName);
-    } // createObject(String,String):Object
-
-    /**
-     * Finds the implementation Class object in the specified order.  The
-     * specified order is the following:
-     * <ol>
-     *  <li>query the system property using <code>System.getProperty</code>
-     *  <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
-     *  <li>read <code>META-INF/services/<i>factoryId</i></code> file
-     *  <li>use fallback classname
-     * </ol>
-     *
-     * @return instance of factory, never null
-     *
-     * @param factoryId             Name of the factory to find, same as
-     *                              a property name
-     * @param propertiesFilename The filename in the $java.home/lib directory
-     *                           of the properties file.  If none specified,
-     *                           ${java.home}/lib/xalan.properties will be used.
-     * @param fallbackClassName     Implementation class name, if nothing else
-     *                              is found.  Use null to mean no fallback.
-     *
-     * @exception ObjectFactory.ConfigurationError
-     */
-    static Object createObject(String factoryId,
-                                      String propertiesFilename,
-                                      String fallbackClassName)
-        throws ConfigurationError
-    {
-        Class factoryClass = lookUpFactoryClass(factoryId,
-                                                propertiesFilename,
-                                                fallbackClassName);
-
-        if (factoryClass == null) {
-            throw new ConfigurationError(
-                "Provider for " + factoryId + " cannot be found", null);
-        }
-
-        try{
-            Object instance = factoryClass.newInstance();
-            if (DEBUG) debugPrintln("created new instance of factory " + factoryId);
-            return instance;
-        } catch (Exception x) {
-            throw new ConfigurationError(
-                "Provider for factory " + factoryId
-                    + " could not be instantiated: " + x, x);
-        }
-    } // createObject(String,String,String):Object
-
-    /**
-     * Finds the implementation Class object in the specified order.  The
-     * specified order is the following:
-     * <ol>
-     *  <li>query the system property using <code>System.getProperty</code>
-     *  <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
-     *  <li>read <code>META-INF/services/<i>factoryId</i></code> file
-     *  <li>use fallback classname
-     * </ol>
-     *
-     * @return Class object of factory, never null
-     *
-     * @param factoryId             Name of the factory to find, same as
-     *                              a property name
-     * @param propertiesFilename The filename in the $java.home/lib directory
-     *                           of the properties file.  If none specified,
-     *                           ${java.home}/lib/xalan.properties will be used.
-     * @param fallbackClassName     Implementation class name, if nothing else
-     *                              is found.  Use null to mean no fallback.
-     *
-     * @exception ObjectFactory.ConfigurationError
-     */
-    static Class lookUpFactoryClass(String factoryId)
-        throws ConfigurationError
-    {
-        return lookUpFactoryClass(factoryId, null, null);
-    } // lookUpFactoryClass(String):Class
-
-    /**
-     * Finds the implementation Class object in the specified order.  The
-     * specified order is the following:
-     * <ol>
-     *  <li>query the system property using <code>System.getProperty</code>
-     *  <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
-     *  <li>read <code>META-INF/services/<i>factoryId</i></code> file
-     *  <li>use fallback classname
-     * </ol>
-     *
-     * @return Class object that provides factory service, never null
-     *
-     * @param factoryId             Name of the factory to find, same as
-     *                              a property name
-     * @param propertiesFilename The filename in the $java.home/lib directory
-     *                           of the properties file.  If none specified,
-     *                           ${java.home}/lib/xalan.properties will be used.
-     * @param fallbackClassName     Implementation class name, if nothing else
-     *                              is found.  Use null to mean no fallback.
-     *
-     * @exception ObjectFactory.ConfigurationError
-     */
-    static Class lookUpFactoryClass(String factoryId,
-                                           String propertiesFilename,
-                                           String fallbackClassName)
-        throws ConfigurationError
-    {
-        String factoryClassName = lookUpFactoryClassName(factoryId,
-                                                         propertiesFilename,
-                                                         fallbackClassName);
-        ClassLoader cl = findClassLoader();
-
-        if (factoryClassName == null) {
-            factoryClassName = fallbackClassName;
-        }
-
-        // assert(className != null);
-        try{
-            Class providerClass = findProviderClass(factoryClassName,
-                                                    cl,
-                                                    true);
-            if (DEBUG) debugPrintln("created new instance of " + providerClass +
-                   " using ClassLoader: " + cl);
-            return providerClass;
-        } catch (ClassNotFoundException x) {
-            throw new ConfigurationError(
-                "Provider " + factoryClassName + " not found", x);
-        } catch (Exception x) {
-            throw new ConfigurationError(
-                "Provider "+factoryClassName+" could not be instantiated: "+x,
-                x);
-        }
-    } // lookUpFactoryClass(String,String,String):Class
-
-    /**
-     * Finds the name of the required implementation class in the specified
-     * order.  The specified order is the following:
-     * <ol>
-     *  <li>query the system property using <code>System.getProperty</code>
-     *  <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
-     *  <li>read <code>META-INF/services/<i>factoryId</i></code> file
-     *  <li>use fallback classname
-     * </ol>
-     *
-     * @return name of class that provides factory service, never null
-     *
-     * @param factoryId             Name of the factory to find, same as
-     *                              a property name
-     * @param propertiesFilename The filename in the $java.home/lib directory
-     *                           of the properties file.  If none specified,
-     *                           ${java.home}/lib/xalan.properties will be used.
-     * @param fallbackClassName     Implementation class name, if nothing else
-     *                              is found.  Use null to mean no fallback.
-     *
-     * @exception ObjectFactory.ConfigurationError
-     */
-    static String lookUpFactoryClassName(String factoryId,
-                                                String propertiesFilename,
-                                                String fallbackClassName)
-    {
-        SecuritySupport ss = SecuritySupport.getInstance();
-
-        // Use the system property first
-        try {
-            String systemProp = ss.getSystemProperty(factoryId);
-            if (systemProp != null) {
-                if (DEBUG) debugPrintln("found system property, value=" + systemProp);
-                return systemProp;
-            }
-        } catch (SecurityException se) {
-            // Ignore and continue w/ next location
-        }
-
-        // Try to read from propertiesFilename, or
-        // $java.home/lib/xalan.properties
-        String factoryClassName = null;
-        // no properties file name specified; use
-        // $JAVA_HOME/lib/xalan.properties:
-        if (propertiesFilename == null) {
-            File propertiesFile = null;
-            boolean propertiesFileExists = false;
-            try {
-                String javah = ss.getSystemProperty("java.home");
-                propertiesFilename = javah + File.separator +
-                    "lib" + File.separator + DEFAULT_PROPERTIES_FILENAME;
-                propertiesFile = new File(propertiesFilename);
-                propertiesFileExists = ss.getFileExists(propertiesFile);
-            } catch (SecurityException e) {
-                // try again...
-                fLastModified = -1;
-                fXalanProperties = null;
-            }
-
-            synchronized (ObjectFactory.class) {
-                boolean loadProperties = false;
-                FileInputStream fis = null;
-                try {
-                    // file existed last time
-                    if(fLastModified >= 0) {
-                        if(propertiesFileExists &&
-                                (fLastModified < (fLastModified = ss.getLastModified(propertiesFile)))) {
-                            loadProperties = true;
-                        } else {
-                            // file has stopped existing...
-                            if(!propertiesFileExists) {
-                                fLastModified = -1;
-                                fXalanProperties = null;
-                            } // else, file wasn't modified!
-                        }
-                    } else {
-                        // file has started to exist:
-                        if(propertiesFileExists) {
-                            loadProperties = true;
-                            fLastModified = ss.getLastModified(propertiesFile);
-                        } // else, nothing's changed
-                    }
-                    if(loadProperties) {
-                        // must never have attempted to read xalan.properties
-                        // before (or it's outdeated)
-                        fXalanProperties = new Properties();
-                        fis = ss.getFileInputStream(propertiesFile);
-                        fXalanProperties.load(fis);
-                    }
-                } catch (Exception x) {
-                    fXalanProperties = null;
-                    fLastModified = -1;
-                    // assert(x instanceof FileNotFoundException
-                    //        || x instanceof SecurityException)
-                    // In both cases, ignore and continue w/ next location
-                }
-                finally {
-                    // try to close the input stream if one was opened.
-                    if (fis != null) {
-                        try {
-                            fis.close();
-                        }
-                        // Ignore the exception.
-                        catch (IOException exc) {}
-                    }
-                }
-            }
-            if(fXalanProperties != null) {
-                factoryClassName = fXalanProperties.getProperty(factoryId);
-            }
-        } else {
-            FileInputStream fis = null;
-            try {
-                fis = ss.getFileInputStream(new File(propertiesFilename));
-                Properties props = new Properties();
-                props.load(fis);
-                factoryClassName = props.getProperty(factoryId);
-            } catch (Exception x) {
-                // assert(x instanceof FileNotFoundException
-                //        || x instanceof SecurityException)
-                // In both cases, ignore and continue w/ next location
-            }
-            finally {
-                // try to close the input stream if one was opened.
-                if (fis != null) {
-                    try {
-                        fis.close();
-                    }
-                    // Ignore the exception.
-                    catch (IOException exc) {}
-                }
-            }
-        }
-        if (factoryClassName != null) {
-            if (DEBUG) debugPrintln("found in " + propertiesFilename + ", value="
-                          + factoryClassName);
-            return factoryClassName;
-        }
-
-        // Try Jar Service Provider Mechanism
-        return findJarServiceProviderName(factoryId);
-    } // lookUpFactoryClass(String,String):String
-
-    //
-    // Private static methods
-    //
-
-    /** Prints a message to standard error if debugging is enabled. */
-    private static void debugPrintln(String msg) {
-        System.err.println("JAXP: " + msg);
-    } // debugPrintln(String)
-
-    /**
-     * Figure out which ClassLoader to use.  For JDK 1.2 and later use
-     * the context ClassLoader.
-     */
-    static ClassLoader findClassLoader()
-        throws ConfigurationError
-    {
-        SecuritySupport ss = SecuritySupport.getInstance();
-
-        // Figure out which ClassLoader to use for loading the provider
-        // class.  If there is a Context ClassLoader then use it.
-        ClassLoader context = ss.getContextClassLoader();
-        ClassLoader system = ss.getSystemClassLoader();
-
-        ClassLoader chain = system;
-        while (true) {
-            if (context == chain) {
-                // Assert: we are on JDK 1.1 or we have no Context ClassLoader
-                // or any Context ClassLoader in chain of system classloader
-                // (including extension ClassLoader) so extend to widest
-                // ClassLoader (always look in system ClassLoader if Xalan
-                // is in boot/extension/system classpath and in current
-                // ClassLoader otherwise); normal classloaders delegate
-                // back to system ClassLoader first so this widening doesn't
-                // change the fact that context ClassLoader will be consulted
-                ClassLoader current = ObjectFactory.class.getClassLoader();
-
-                chain = system;
-                while (true) {
-                    if (current == chain) {
-                        // Assert: Current ClassLoader in chain of
-                        // boot/extension/system ClassLoaders
-                        return system;
-                    }
-                    if (chain == null) {
-                        break;
-                    }
-                    chain = ss.getParentClassLoader(chain);
-                }
-
-                // Assert: Current ClassLoader not in chain of
-                // boot/extension/system ClassLoaders
-                return current;
-            }
-
-            if (chain == null) {
-                // boot ClassLoader reached
-                break;
-            }
-
-            // Check for any extension ClassLoaders in chain up to
-            // boot ClassLoader
-            chain = ss.getParentClassLoader(chain);
-        };
-
-        // Assert: Context ClassLoader not in chain of
-        // boot/extension/system ClassLoaders
-        return context;
-    } // findClassLoader():ClassLoader
-
-    /**
-     * Create an instance of a class using the specified ClassLoader
-     */
-    static Object newInstance(String className, ClassLoader cl,
-                                      boolean doFallback)
-        throws ConfigurationError
-    {
-        // assert(className != null);
-        try{
-            Class providerClass = findProviderClass(className, cl, doFallback);
-            Object instance = providerClass.newInstance();
-            if (DEBUG) debugPrintln("created new instance of " + providerClass +
-                   " using ClassLoader: " + cl);
-            return instance;
-        } catch (ClassNotFoundException x) {
-            throw new ConfigurationError(
-                "Provider " + className + " not found", x);
-        } catch (Exception x) {
-            throw new ConfigurationError(
-                "Provider " + className + " could not be instantiated: " + x,
-                x);
-        }
-    }
-
-    /**
-     * Find a Class using the specified ClassLoader
-     */
-    static Class findProviderClass(String className, ClassLoader cl,
-                                           boolean doFallback)
-        throws ClassNotFoundException, ConfigurationError
-    {
-        //throw security exception if the calling thread is not allowed to access the
-        //class. Restrict the access to the package classes as specified in java.security policy.
-        SecurityManager security = System.getSecurityManager();
-        try{
-                if (security != null){
-                    final int lastDot = className.lastIndexOf(".");
-                    String packageName = className;
-                    if (lastDot != -1) packageName = className.substring(0, lastDot);
-                    security.checkPackageAccess(packageName);
-                 }
-        }catch(SecurityException e){
-            throw e;
-        }
-
-        Class providerClass;
-        if (cl == null) {
-            // XXX Use the bootstrap ClassLoader.  There is no way to
-            // load a class using the bootstrap ClassLoader that works
-            // in both JDK 1.1 and Java 2.  However, this should still
-            // work b/c the following should be true:
-            //
-            // (cl == null) iff current ClassLoader == null
-            //
-            // Thus Class.forName(String) will use the current
-            // ClassLoader which will be the bootstrap ClassLoader.
-            providerClass = Class.forName(className);
-        } else {
-            try {
-                providerClass = cl.loadClass(className);
-            } catch (ClassNotFoundException x) {
-                if (doFallback) {
-                    // Fall back to current classloader
-                    ClassLoader current = ObjectFactory.class.getClassLoader();
-                    if (current == null) {
-                        providerClass = Class.forName(className);
-                    } else if (cl != current) {
-                        cl = current;
-                        providerClass = cl.loadClass(className);
-                    } else {
-                        throw x;
-                    }
-                } else {
-                    throw x;
-                }
-            }
-        }
-
-        return providerClass;
-    }
-
-    /**
-     * Find the name of service provider using Jar Service Provider Mechanism
-     *
-     * @return instance of provider class if found or null
-     */
-    private static String findJarServiceProviderName(String factoryId)
-    {
-        SecuritySupport ss = SecuritySupport.getInstance();
-        String serviceId = SERVICES_PATH + factoryId;
-        InputStream is = null;
-
-        // First try the Context ClassLoader
-        ClassLoader cl = findClassLoader();
-
-        is = ss.getResourceAsStream(cl, serviceId);
-
-        // If no provider found then try the current ClassLoader
-        if (is == null) {
-            ClassLoader current = ObjectFactory.class.getClassLoader();
-            if (cl != current) {
-                cl = current;
-                is = ss.getResourceAsStream(cl, serviceId);
-            }
-        }
-
-        if (is == null) {
-            // No provider found
-            return null;
-        }
-
-        if (DEBUG) debugPrintln("found jar resource=" + serviceId +
-               " using ClassLoader: " + cl);
-
-        // Read the service provider name in UTF-8 as specified in
-        // the jar spec.  Unfortunately this fails in Microsoft
-        // VJ++, which does not implement the UTF-8
-        // encoding. Theoretically, we should simply let it fail in
-        // that case, since the JVM is obviously broken if it
-        // doesn't support such a basic standard.  But since there
-        // are still some users attempting to use VJ++ for
-        // development, we have dropped in a fallback which makes a
-        // second attempt using the platform's default encoding. In
-        // VJ++ this is apparently ASCII, which is a subset of
-        // UTF-8... and since the strings we'll be reading here are
-        // also primarily limited to the 7-bit ASCII range (at
-        // least, in English versions), this should work well
-        // enough to keep us on the air until we're ready to
-        // officially decommit from VJ++. [Edited comment from
-        // jkesselm]
-        BufferedReader rd;
-        try {
-            rd = new BufferedReader(new InputStreamReader(is, "UTF-8"));
-        } catch (java.io.UnsupportedEncodingException e) {
-            rd = new BufferedReader(new InputStreamReader(is));
-        }
-
-        String factoryClassName = null;
-        try {
-            // XXX Does not handle all possible input as specified by the
-            // Jar Service Provider specification
-            factoryClassName = rd.readLine();
-        } catch (IOException x) {
-            // No provider found
-            return null;
-        }
-        finally {
-            try {
-                // try to close the reader.
-                rd.close();
-            }
-            // Ignore the exception.
-            catch (IOException exc) {}
-        }
-
-        if (factoryClassName != null &&
-            ! "".equals(factoryClassName)) {
-            if (DEBUG) debugPrintln("found in resource, value="
-                   + factoryClassName);
-
-            // Note: here we do not want to fall back to the current
-            // ClassLoader because we want to avoid the case where the
-            // resource file was found using one ClassLoader and the
-            // provider class was instantiated using a different one.
-            return factoryClassName;
-        }
-
-        // No provider found
-        return null;
-    }
-
-    //
-    // Classes
-    //
-
-    /**
-     * A configuration error.
-     */
-    static class ConfigurationError
-        extends Error {
-                static final long serialVersionUID = -7640369932165775029L;
-        //
-        // Data
-        //
-
-        /** Exception. */
-        private Exception exception;
-
-        //
-        // Constructors
-        //
-
-        /**
-         * Construct a new instance with the specified detail string and
-         * exception.
-         */
-        ConfigurationError(String msg, Exception x) {
-            super(msg);
-            this.exception = x;
-        } // <init>(String,Exception)
-
-        //
-        // Public methods
-        //
-
-        /** Returns the exception associated to this error. */
-        Exception getException() {
-            return exception;
-        } // getException():Exception
-
-    } // class ConfigurationError
-
-} // class ObjectFactory
--- a/jaxp/src/com/sun/org/apache/xalan/internal/lib/SecuritySupport.java	Thu Apr 12 08:38:26 2012 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,127 +0,0 @@
-/*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
- */
-/*
- * Copyright 2002-2004 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * 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: SecuritySupport.java,v 1.1.2.1 2005/08/01 02:08:48 jeffsuttor Exp $
- */
-
-package com.sun.org.apache.xalan.internal.lib;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.InputStream;
-
-import java.util.Properties;
-
-/**
- * This class is duplicated for each Xalan-Java subpackage so keep it in sync.
- * It is package private and therefore is not exposed as part of the Xalan-Java
- * API.
- *
- * Base class with security related methods that work on JDK 1.1.
- */
-class SecuritySupport {
-
-    /*
-     * Make this of type Object so that the verifier won't try to
-     * prove its type, thus possibly trying to load the SecuritySupport12
-     * class.
-     */
-    private static final Object securitySupport;
-
-    static {
-        SecuritySupport ss = null;
-        try {
-            Class c = Class.forName("java.security.AccessController");
-            // if that worked, we're on 1.2.
-            /*
-            // don't reference the class explicitly so it doesn't
-            // get dragged in accidentally.
-            c = Class.forName("javax.mail.SecuritySupport12");
-            Constructor cons = c.getConstructor(new Class[] { });
-            ss = (SecuritySupport)cons.newInstance(new Object[] { });
-            */
-            /*
-             * Unfortunately, we can't load the class using reflection
-             * because the class is package private.  And the class has
-             * to be package private so the APIs aren't exposed to other
-             * code that could use them to circumvent security.  Thus,
-             * we accept the risk that the direct reference might fail
-             * on some JDK 1.1 JVMs, even though we would never execute
-             * this code in such a case.  Sigh...
-             */
-            ss = new SecuritySupport12();
-        } catch (Exception ex) {
-            // ignore it
-        } finally {
-            if (ss == null)
-                ss = new SecuritySupport();
-            securitySupport = ss;
-        }
-    }
-
-    /**
-     * Return an appropriate instance of this class, depending on whether
-     * we're on a JDK 1.1 or J2SE 1.2 (or later) system.
-     */
-    static SecuritySupport getInstance() {
-        return (SecuritySupport)securitySupport;
-    }
-
-    ClassLoader getContextClassLoader() {
-        return null;
-    }
-
-    ClassLoader getSystemClassLoader() {
-        return null;
-    }
-
-    ClassLoader getParentClassLoader(ClassLoader cl) {
-        return null;
-    }
-
-    String getSystemProperty(String propName) {
-        return System.getProperty(propName);
-    }
-
-    FileInputStream getFileInputStream(File file)
-        throws FileNotFoundException
-    {
-        return new FileInputStream(file);
-    }
-
-    InputStream getResourceAsStream(ClassLoader cl, String name) {
-        InputStream ris;
-        if (cl == null) {
-            ris = ClassLoader.getSystemResourceAsStream(name);
-        } else {
-            ris = cl.getResourceAsStream(name);
-        }
-        return ris;
-    }
-
-    boolean getFileExists(File f) {
-        return f.exists();
-    }
-
-    long getLastModified(File f) {
-        return f.lastModified();
-    }
-}
--- a/jaxp/src/com/sun/org/apache/xalan/internal/lib/SecuritySupport12.java	Thu Apr 12 08:38:26 2012 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,148 +0,0 @@
-/*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
- */
-/*
- * Copyright 2002-2004 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * 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: SecuritySupport12.java,v 1.1.2.1 2005/08/01 02:08:47 jeffsuttor Exp $
- */
-
-package com.sun.org.apache.xalan.internal.lib;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.InputStream;
-
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
-
-import java.util.Properties;
-
-/**
- * This class is duplicated for each Xalan-Java subpackage so keep it in sync.
- * It is package private and therefore is not exposed as part of the Xalan-Java
- * API.
- *
- * Security related methods that only work on J2SE 1.2 and newer.
- */
-class SecuritySupport12 extends SecuritySupport {
-
-    ClassLoader getContextClassLoader() {
-        return (ClassLoader)
-                AccessController.doPrivileged(new PrivilegedAction() {
-            public Object run() {
-                ClassLoader cl = null;
-                try {
-                    cl = Thread.currentThread().getContextClassLoader();
-                } catch (SecurityException ex) { }
-                return cl;
-            }
-        });
-    }
-
-    ClassLoader getSystemClassLoader() {
-        return (ClassLoader)
-            AccessController.doPrivileged(new PrivilegedAction() {
-                public Object run() {
-                    ClassLoader cl = null;
-                    try {
-                        cl = ClassLoader.getSystemClassLoader();
-                    } catch (SecurityException ex) {}
-                    return cl;
-                }
-            });
-    }
-
-    ClassLoader getParentClassLoader(final ClassLoader cl) {
-        return (ClassLoader)
-            AccessController.doPrivileged(new PrivilegedAction() {
-                public Object run() {
-                    ClassLoader parent = null;
-                    try {
-                        parent = cl.getParent();
-                    } catch (SecurityException ex) {}
-
-                    // eliminate loops in case of the boot
-                    // ClassLoader returning itself as a parent
-                    return (parent == cl) ? null : parent;
-                }
-            });
-    }
-
-    String getSystemProperty(final String propName) {
-        return (String)
-            AccessController.doPrivileged(new PrivilegedAction() {
-                public Object run() {
-                    return System.getProperty(propName);
-                }
-            });
-    }
-
-    FileInputStream getFileInputStream(final File file)
-        throws FileNotFoundException
-    {
-        try {
-            return (FileInputStream)
-                AccessController.doPrivileged(new PrivilegedExceptionAction() {
-                    public Object run() throws FileNotFoundException {
-                        return new FileInputStream(file);
-                    }
-                });
-        } catch (PrivilegedActionException e) {
-            throw (FileNotFoundException)e.getException();
-        }
-    }
-
-    InputStream getResourceAsStream(final ClassLoader cl,
-                                           final String name)
-    {
-        return (InputStream)
-            AccessController.doPrivileged(new PrivilegedAction() {
-                public Object run() {
-                    InputStream ris;
-                    if (cl == null) {
-                        ris = ClassLoader.getSystemResourceAsStream(name);
-                    } else {
-                        ris = cl.getResourceAsStream(name);
-                    }
-                    return ris;
-                }
-            });
-    }
-
-    boolean getFileExists(final File f) {
-    return ((Boolean)
-            AccessController.doPrivileged(new PrivilegedAction() {
-                public Object run() {
-                    return new Boolean(f.exists());
-                }
-            })).booleanValue();
-    }
-
-    long getLastModified(final File f) {
-    return ((Long)
-            AccessController.doPrivileged(new PrivilegedAction() {
-                public Object run() {
-                    return new Long(f.lastModified());
-                }
-            })).longValue();
-    }
-
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/utils/ConfigurationError.java	Tue Apr 17 11:17:59 2012 -0700
@@ -0,0 +1,61 @@
+/*
+ * reserved comment block
+ * DO NOT REMOVE OR ALTER!
+ */
+/*
+ * Copyright 2001-2004 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.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * 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: ObjectFactory.java,v 1.2.4.1 2005/09/15 02:39:54 jeffsuttor Exp $
+ */
+
+package com.sun.org.apache.xalan.internal.utils;
+
+/**
+ * A configuration error. This was an internal class in ObjectFactory previously
+ */
+public final class ConfigurationError
+    extends Error {
+
+    //
+    // Data
+    //
+
+    /** Exception. */
+    private Exception exception;
+
+    //
+    // Constructors
+    //
+
+    /**
+     * Construct a new instance with the specified detail string and
+     * exception.
+     */
+    ConfigurationError(String msg, Exception x) {
+        super(msg);
+        this.exception = x;
+    } // <init>(String,Exception)
+
+    //
+    // methods
+    //
+
+    /** Returns the exception associated to this error. */
+    public Exception getException() {
+        return exception;
+    } // getException():Exception
+
+} // class ConfigurationError
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/utils/FactoryImpl.java	Tue Apr 17 11:17:59 2012 -0700
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2011 Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.org.apache.xalan.internal.utils;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.SAXParserFactory;
+
+/**
+ *
+ * @author huizhe wang
+ */
+public class FactoryImpl {
+
+    static final String DBF = "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl";
+    static final String SF = "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl";
+
+    static public DocumentBuilderFactory getDOMFactory(boolean useServicesMechanism) {
+        DocumentBuilderFactory dbf =
+            useServicesMechanism ?
+            DocumentBuilderFactory.newInstance() :
+            DocumentBuilderFactory.newInstance( DBF,
+                FactoryImpl.class.getClassLoader());
+
+        return dbf;
+    }
+    static public SAXParserFactory getSAXFactory(boolean useServicesMechanism) {
+                SAXParserFactory factory =
+                    useServicesMechanism ?
+                    SAXParserFactory.newInstance() :
+                    SAXParserFactory.newInstance(SF,
+                        FactoryImpl.class.getClassLoader());
+                return factory;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/utils/ObjectFactory.java	Tue Apr 17 11:17:59 2012 -0700
@@ -0,0 +1,652 @@
+/*
+ * reserved comment block
+ * DO NOT REMOVE OR ALTER!
+ */
+/*
+ * Copyright 2001-2004 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.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * 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: ObjectFactory.java,v 1.2.4.1 2005/09/15 02:39:54 jeffsuttor Exp $
+ */
+
+package com.sun.org.apache.xalan.internal.utils;
+
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.File;
+import java.io.FileInputStream;
+
+import java.util.Properties;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+
+/**
+ * This class is duplicated for each JAXP subpackage so keep it in sync.
+ * It is package private and therefore is not exposed as part of the JAXP
+ * API.
+ * <p>
+ * This code is designed to implement the JAXP 1.1 spec pluggability
+ * feature and is designed to run on JDK version 1.1 and
+ * later, and to compile on JDK 1.2 and onward.
+ * The code also runs both as part of an unbundled jar file and
+ * when bundled as part of the JDK.
+ * <p>
+ * This class was moved from the <code>javax.xml.parsers.ObjectFactory</code>
+ * class and modified to be used as a general utility for creating objects
+ * dynamically.
+ *
+ * @version $Id: ObjectFactory.java,v 1.11 2010-11-01 04:34:25 joehw Exp $
+ */
+public class ObjectFactory {
+
+    //
+    // Constants
+    //
+
+    // name of default properties file to look for in JDK's jre/lib directory
+    private static final String DEFAULT_PROPERTIES_FILENAME =
+                                                     "xalan.properties";
+
+    private static final String SERVICES_PATH = "META-INF/services/";
+
+    /** Set to true for debugging */
+    private static final boolean DEBUG = false;
+
+    /** cache the contents of the xalan.properties file.
+     *  Until an attempt has been made to read this file, this will
+     * be null; if the file does not exist or we encounter some other error
+     * during the read, this will be empty.
+     */
+    private static Properties fXalanProperties = null;
+
+    /***
+     * Cache the time stamp of the xalan.properties file so
+     * that we know if it's been modified and can invalidate
+     * the cache when necessary.
+     */
+    private static long fLastModified = -1;
+
+    //
+    // Public static methods
+    //
+
+    /**
+     * Finds the implementation Class object in the specified order.  The
+     * specified order is the following:
+     * <ol>
+     *  <li>query the system property using <code>System.getProperty</code>
+     *  <li>read <code>META-INF/services/<i>factoryId</i></code> file
+     *  <li>use fallback classname
+     * </ol>
+     *
+     * @return instance of factory, never null
+     *
+     * @param factoryId             Name of the factory to find, same as
+     *                              a property name
+     * @param fallbackClassName     Implementation class name, if nothing else
+     *                              is found.  Use null to mean no fallback.
+     *
+     * @exception ObjectFactory.ConfigurationError
+     */
+    public static Object createObject(String factoryId, String fallbackClassName)
+        throws ConfigurationError {
+        return createObject(factoryId, null, fallbackClassName);
+    } // createObject(String,String):Object
+
+    /**
+     * Finds the implementation Class object in the specified order.  The
+     * specified order is the following:
+     * <ol>
+     *  <li>query the system property using <code>System.getProperty</code>
+     *  <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
+     *  <li>read <code>META-INF/services/<i>factoryId</i></code> file
+     *  <li>use fallback classname
+     * </ol>
+     *
+     * @return instance of factory, never null
+     *
+     * @param factoryId             Name of the factory to find, same as
+     *                              a property name
+     * @param propertiesFilename The filename in the $java.home/lib directory
+     *                           of the properties file.  If none specified,
+     *                           ${java.home}/lib/xalan.properties will be used.
+     * @param fallbackClassName     Implementation class name, if nothing else
+     *                              is found.  Use null to mean no fallback.
+     *
+     * @exception ObjectFactory.ConfigurationError
+     */
+    static Object createObject(String factoryId,
+                                      String propertiesFilename,
+                                      String fallbackClassName)
+        throws ConfigurationError
+    {
+        Class factoryClass = lookUpFactoryClass(factoryId,
+                                                propertiesFilename,
+                                                fallbackClassName);
+
+        if (factoryClass == null) {
+            throw new ConfigurationError(
+                "Provider for " + factoryId + " cannot be found", null);
+        }
+
+        try{
+            Object instance = factoryClass.newInstance();
+            if (DEBUG) debugPrintln("created new instance of factory " + factoryId);
+            return instance;
+        } catch (Exception x) {
+            throw new ConfigurationError(
+                "Provider for factory " + factoryId
+                    + " could not be instantiated: " + x, x);
+        }
+    } // createObject(String,String,String):Object
+
+    /**
+     * Finds the implementation Class object in the specified order.  The
+     * specified order is the following:
+     * <ol>
+     *  <li>query the system property using <code>System.getProperty</code>
+     *  <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
+     *  <li>read <code>META-INF/services/<i>factoryId</i></code> file
+     *  <li>use fallback classname
+     * </ol>
+     *
+     * @return Class object of factory, never null
+     *
+     * @param factoryId             Name of the factory to find, same as
+     *                              a property name
+     * @param propertiesFilename The filename in the $java.home/lib directory
+     *                           of the properties file.  If none specified,
+     *                           ${java.home}/lib/xalan.properties will be used.
+     * @param fallbackClassName     Implementation class name, if nothing else
+     *                              is found.  Use null to mean no fallback.
+     *
+     * @exception ObjectFactory.ConfigurationError
+     */
+    public static Class lookUpFactoryClass(String factoryId)
+        throws ConfigurationError
+    {
+        return lookUpFactoryClass(factoryId, null, null);
+    } // lookUpFactoryClass(String):Class
+
+    /**
+     * Finds the implementation Class object in the specified order.  The
+     * specified order is the following:
+     * <ol>
+     *  <li>query the system property using <code>System.getProperty</code>
+     *  <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
+     *  <li>read <code>META-INF/services/<i>factoryId</i></code> file
+     *  <li>use fallback classname
+     * </ol>
+     *
+     * @return Class object that provides factory service, never null
+     *
+     * @param factoryId             Name of the factory to find, same as
+     *                              a property name
+     * @param propertiesFilename The filename in the $java.home/lib directory
+     *                           of the properties file.  If none specified,
+     *                           ${java.home}/lib/xalan.properties will be used.
+     * @param fallbackClassName     Implementation class name, if nothing else
+     *                              is found.  Use null to mean no fallback.
+     *
+     * @exception ObjectFactory.ConfigurationError
+     */
+    public static Class lookUpFactoryClass(String factoryId,
+                                           String propertiesFilename,
+                                           String fallbackClassName)
+        throws ConfigurationError
+    {
+        String factoryClassName = lookUpFactoryClassName(factoryId,
+                                                         propertiesFilename,
+                                                         fallbackClassName);
+        ClassLoader cl = findClassLoader();
+
+        if (factoryClassName == null) {
+            factoryClassName = fallbackClassName;
+        }
+
+        // assert(className != null);
+        try{
+            Class providerClass = findProviderClass(factoryClassName,
+                                                    cl,
+                                                    true);
+            if (DEBUG) debugPrintln("created new instance of " + providerClass +
+                   " using ClassLoader: " + cl);
+            return providerClass;
+        } catch (ClassNotFoundException x) {
+            throw new ConfigurationError(
+                "Provider " + factoryClassName + " not found", x);
+        } catch (Exception x) {
+            throw new ConfigurationError(
+                "Provider "+factoryClassName+" could not be instantiated: "+x,
+                x);
+        }
+    } // lookUpFactoryClass(String,String,String):Class
+
+    /**
+     * Finds the name of the required implementation class in the specified
+     * order.  The specified order is the following:
+     * <ol>
+     *  <li>query the system property using <code>System.getProperty</code>
+     *  <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
+     *  <li>read <code>META-INF/services/<i>factoryId</i></code> file
+     *  <li>use fallback classname
+     * </ol>
+     *
+     * @return name of class that provides factory service, never null
+     *
+     * @param factoryId             Name of the factory to find, same as
+     *                              a property name
+     * @param propertiesFilename The filename in the $java.home/lib directory
+     *                           of the properties file.  If none specified,
+     *                           ${java.home}/lib/xalan.properties will be used.
+     * @param fallbackClassName     Implementation class name, if nothing else
+     *                              is found.  Use null to mean no fallback.
+     *
+     * @exception ObjectFactory.ConfigurationError
+     */
+    static String lookUpFactoryClassName(String factoryId,
+                                                String propertiesFilename,
+                                                String fallbackClassName)
+    {
+        // Use the system property first
+        try {
+            String systemProp = SecuritySupport.getSystemProperty(factoryId);
+            if (systemProp != null) {
+                if (DEBUG) debugPrintln("found system property, value=" + systemProp);
+                return systemProp;
+            }
+        } catch (SecurityException se) {
+            // Ignore and continue w/ next location
+        }
+
+        // Try to read from propertiesFilename, or
+        // $java.home/lib/xalan.properties
+        String factoryClassName = null;
+        // no properties file name specified; use
+        // $JAVA_HOME/lib/xalan.properties:
+        if (propertiesFilename == null) {
+            File propertiesFile = null;
+            boolean propertiesFileExists = false;
+            try {
+                String javah = SecuritySupport.getSystemProperty("java.home");
+                propertiesFilename = javah + File.separator +
+                    "lib" + File.separator + DEFAULT_PROPERTIES_FILENAME;
+                propertiesFile = new File(propertiesFilename);
+                propertiesFileExists = SecuritySupport.getFileExists(propertiesFile);
+            } catch (SecurityException e) {
+                // try again...
+                fLastModified = -1;
+                fXalanProperties = null;
+            }
+
+            synchronized (ObjectFactory.class) {
+                boolean loadProperties = false;
+                FileInputStream fis = null;
+                try {
+                    // file existed last time
+                    if(fLastModified >= 0) {
+                        if(propertiesFileExists &&
+                                (fLastModified < (fLastModified = SecuritySupport.getLastModified(propertiesFile)))) {
+                            loadProperties = true;
+                        } else {
+                            // file has stopped existing...
+                            if(!propertiesFileExists) {
+                                fLastModified = -1;
+                                fXalanProperties = null;
+                            } // else, file wasn't modified!
+                        }
+                    } else {
+                        // file has started to exist:
+                        if(propertiesFileExists) {
+                            loadProperties = true;
+                            fLastModified = SecuritySupport.getLastModified(propertiesFile);
+                        } // else, nothing's changed
+                    }
+                    if(loadProperties) {
+                        // must never have attempted to read xalan.properties
+                        // before (or it's outdeated)
+                        fXalanProperties = new Properties();
+                        fis = SecuritySupport.getFileInputStream(propertiesFile);
+                        fXalanProperties.load(fis);
+                    }
+                } catch (Exception x) {
+                    fXalanProperties = null;
+                    fLastModified = -1;
+                    // assert(x instanceof FileNotFoundException
+                    //        || x instanceof SecurityException)
+                    // In both cases, ignore and continue w/ next location
+                }
+                finally {
+                    // try to close the input stream if one was opened.
+                    if (fis != null) {
+                        try {
+                            fis.close();
+                        }
+                        // Ignore the exception.
+                        catch (IOException exc) {}
+                    }
+                }
+            }
+            if(fXalanProperties != null) {
+                factoryClassName = fXalanProperties.getProperty(factoryId);
+            }
+        } else {
+            FileInputStream fis = null;
+            try {
+                fis = SecuritySupport.getFileInputStream(new File(propertiesFilename));
+                Properties props = new Properties();
+                props.load(fis);
+                factoryClassName = props.getProperty(factoryId);
+            } catch (Exception x) {
+                // assert(x instanceof FileNotFoundException
+                //        || x instanceof SecurityException)
+                // In both cases, ignore and continue w/ next location
+            }
+            finally {
+                // try to close the input stream if one was opened.
+                if (fis != null) {
+                    try {
+                        fis.close();
+                    }
+                    // Ignore the exception.
+                    catch (IOException exc) {}
+                }
+            }
+        }
+        if (factoryClassName != null) {
+            if (DEBUG) debugPrintln("found in " + propertiesFilename + ", value="
+                          + factoryClassName);
+            return factoryClassName;
+        }
+
+        // Try Jar Service Provider Mechanism
+        return findJarServiceProviderName(factoryId);
+    } // lookUpFactoryClass(String,String):String
+
+    //
+    // Private static methods
+    //
+
+    /** Prints a message to standard error if debugging is enabled. */
+    private static void debugPrintln(String msg) {
+        if (DEBUG) {
+            System.err.println("JAXP: " + msg);
+        }
+    } // debugPrintln(String)
+
+    /**
+     * Figure out which ClassLoader to use.  For JDK 1.2 and later use
+     * the context ClassLoader.
+     */
+    public static ClassLoader findClassLoader()
+        throws ConfigurationError
+    {
+        if (System.getSecurityManager()!=null) {
+            //this will ensure bootclassloader is used
+            return null;
+        }
+
+        // Figure out which ClassLoader to use for loading the provider
+        // class.  If there is a Context ClassLoader then use it.
+        ClassLoader context = SecuritySupport.getContextClassLoader();
+        ClassLoader system = SecuritySupport.getSystemClassLoader();
+
+        ClassLoader chain = system;
+        while (true) {
+            if (context == chain) {
+                // Assert: we are on JDK 1.1 or we have no Context ClassLoader
+                // or any Context ClassLoader in chain of system classloader
+                // (including extension ClassLoader) so extend to widest
+                // ClassLoader (always look in system ClassLoader if Xalan
+                // is in boot/extension/system classpath and in current
+                // ClassLoader otherwise); normal classloaders delegate
+                // back to system ClassLoader first so this widening doesn't
+                // change the fact that context ClassLoader will be consulted
+                ClassLoader current = ObjectFactory.class.getClassLoader();
+
+                chain = system;
+                while (true) {
+                    if (current == chain) {
+                        // Assert: Current ClassLoader in chain of
+                        // boot/extension/system ClassLoaders
+                        return system;
+                    }
+                    if (chain == null) {
+                        break;
+                    }
+                    chain = SecuritySupport.getParentClassLoader(chain);
+                }
+
+                // Assert: Current ClassLoader not in chain of
+                // boot/extension/system ClassLoaders
+                return current;
+            }
+
+            if (chain == null) {
+                // boot ClassLoader reached
+                break;
+            }
+
+            // Check for any extension ClassLoaders in chain up to
+            // boot ClassLoader
+            chain = SecuritySupport.getParentClassLoader(chain);
+        }
+
+        // Assert: Context ClassLoader not in chain of
+        // boot/extension/system ClassLoaders
+        return context;
+    } // findClassLoader():ClassLoader
+
+    /**
+     * Create an instance of a class using the same classloader for the ObjectFactory by default
+     * or bootclassloader when Security Manager is in place
+     */
+    public static Object newInstance(String className, boolean doFallback)
+        throws ConfigurationError
+    {
+        if (System.getSecurityManager()!=null) {
+            return newInstance(className, null, doFallback);
+        } else {
+            return newInstance(className,
+                findClassLoader (), doFallback);
+        }
+    }
+
+    /**
+     * Create an instance of a class using the specified ClassLoader
+     */
+    static Object newInstance(String className, ClassLoader cl,
+                                      boolean doFallback)
+        throws ConfigurationError
+    {
+        // assert(className != null);
+        try{
+            Class providerClass = findProviderClass(className, cl, doFallback);
+            Object instance = providerClass.newInstance();
+            if (DEBUG) debugPrintln("created new instance of " + providerClass +
+                   " using ClassLoader: " + cl);
+            return instance;
+        } catch (ClassNotFoundException x) {
+            throw new ConfigurationError(
+                "Provider " + className + " not found", x);
+        } catch (Exception x) {
+            throw new ConfigurationError(
+                "Provider " + className + " could not be instantiated: " + x,
+                x);
+        }
+    }
+
+    /**
+     * Find a Class using the same classloader for the ObjectFactory by default
+     * or bootclassloader when Security Manager is in place
+     */
+    public static Class findProviderClass(String className, boolean doFallback)
+        throws ClassNotFoundException, ConfigurationError
+    {
+        if (System.getSecurityManager()!=null) {
+            return Class.forName(className);
+        } else {
+            return findProviderClass (className,
+                findClassLoader (), doFallback);
+        }
+    }
+
+    /**
+     * Find a Class using the specified ClassLoader
+     */
+    static Class findProviderClass(String className, ClassLoader cl,
+                                           boolean doFallback)
+        throws ClassNotFoundException, ConfigurationError
+    {
+        //throw security exception if the calling thread is not allowed to access the
+        //class. Restrict the access to the package classes as specified in java.security policy.
+        SecurityManager security = System.getSecurityManager();
+        try{
+                if (security != null){
+                    final int lastDot = className.lastIndexOf(".");
+                    String packageName = className;
+                    if (lastDot != -1) packageName = className.substring(0, lastDot);
+                    security.checkPackageAccess(packageName);
+                 }
+        }catch(SecurityException e){
+            throw e;
+        }
+
+        Class providerClass;
+        if (cl == null) {
+            // XXX Use the bootstrap ClassLoader.  There is no way to
+            // load a class using the bootstrap ClassLoader that works
+            // in both JDK 1.1 and Java 2.  However, this should still
+            // work b/c the following should be true:
+            //
+            // (cl == null) iff current ClassLoader == null
+            //
+            // Thus Class.forName(String) will use the current
+            // ClassLoader which will be the bootstrap ClassLoader.
+            providerClass = Class.forName(className);
+        } else {
+            try {
+                providerClass = cl.loadClass(className);
+            } catch (ClassNotFoundException x) {
+                if (doFallback) {
+                    // Fall back to current classloader
+                    ClassLoader current = ObjectFactory.class.getClassLoader();
+                    if (current == null) {
+                        providerClass = Class.forName(className);
+                    } else if (cl != current) {
+                        cl = current;
+                        providerClass = cl.loadClass(className);
+                    } else {
+                        throw x;
+                    }
+                } else {
+                    throw x;
+                }
+            }
+        }
+
+        return providerClass;
+    }
+
+    /**
+     * Find the name of service provider using Jar Service Provider Mechanism
+     *
+     * @return instance of provider class if found or null
+     */
+    private static String findJarServiceProviderName(String factoryId)
+    {
+        String serviceId = SERVICES_PATH + factoryId;
+        InputStream is = null;
+
+        // First try the Context ClassLoader
+        ClassLoader cl = findClassLoader();
+
+        is = SecuritySupport.getResourceAsStream(cl, serviceId);
+
+        // If no provider found then try the current ClassLoader
+        if (is == null) {
+            ClassLoader current = ObjectFactory.class.getClassLoader();
+            if (cl != current) {
+                cl = current;
+                is = SecuritySupport.getResourceAsStream(cl, serviceId);
+            }
+        }
+
+        if (is == null) {
+            // No provider found
+            return null;
+        }
+
+        if (DEBUG) debugPrintln("found jar resource=" + serviceId +
+               " using ClassLoader: " + cl);
+
+        // Read the service provider name in UTF-8 as specified in
+        // the jar spec.  Unfortunately this fails in Microsoft
+        // VJ++, which does not implement the UTF-8
+        // encoding. Theoretically, we should simply let it fail in
+        // that case, since the JVM is obviously broken if it
+        // doesn't support such a basic standard.  But since there
+        // are still some users attempting to use VJ++ for
+        // development, we have dropped in a fallback which makes a
+        // second attempt using the platform's default encoding. In
+        // VJ++ this is apparently ASCII, which is a subset of
+        // UTF-8... and since the strings we'll be reading here are
+        // also primarily limited to the 7-bit ASCII range (at
+        // least, in English versions), this should work well
+        // enough to keep us on the air until we're ready to
+        // officially decommit from VJ++. [Edited comment from
+        // jkesselm]
+        BufferedReader rd;
+        try {
+            rd = new BufferedReader(new InputStreamReader(is, "UTF-8"));
+        } catch (java.io.UnsupportedEncodingException e) {
+            rd = new BufferedReader(new InputStreamReader(is));
+        }
+
+        String factoryClassName = null;
+        try {
+            // XXX Does not handle all possible input as specified by the
+            // Jar Service Provider specification
+            factoryClassName = rd.readLine();
+        } catch (IOException x) {
+            // No provider found
+            return null;
+        }
+        finally {
+            try {
+                // try to close the reader.
+                rd.close();
+            }
+            // Ignore the exception.
+            catch (IOException exc) {}
+        }
+
+        if (factoryClassName != null &&
+            ! "".equals(factoryClassName)) {
+            if (DEBUG) debugPrintln("found in resource, value="
+                   + factoryClassName);
+
+            // Note: here we do not want to fall back to the current
+            // ClassLoader because we want to avoid the case where the
+            // resource file was found using one ClassLoader and the
+            // provider class was instantiated using a different one.
+            return factoryClassName;
+        }
+
+        // No provider found
+        return null;
+    }
+
+} // class ObjectFactory
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/utils/SecuritySupport.java	Tue Apr 17 11:17:59 2012 -0700
@@ -0,0 +1,166 @@
+/*
+ * reserved comment block
+ * DO NOT REMOVE OR ALTER!
+ */
+/*
+ * Copyright 2002-2004 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.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * 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: SecuritySupport.java,v 1.1.2.1 2005/08/01 02:08:48 jeffsuttor Exp $
+ */
+
+package com.sun.org.apache.xalan.internal.utils;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
+/**
+ * This class is duplicated for each subpackage so keep it in sync.
+ * It is package private and therefore is not exposed as part of any API.
+ *
+ * @xerces.internal
+ */
+public final class SecuritySupport {
+
+    private static final SecuritySupport securitySupport = new SecuritySupport();
+
+    /**
+     * Return an instance of this class.
+     */
+    public static SecuritySupport getInstance() {
+        return securitySupport;
+    }
+
+    static ClassLoader getContextClassLoader() {
+        return (ClassLoader)
+        AccessController.doPrivileged(new PrivilegedAction() {
+            public Object run() {
+                ClassLoader cl = null;
+                try {
+                    cl = Thread.currentThread().getContextClassLoader();
+                } catch (SecurityException ex) { }
+                return cl;
+            }
+        });
+    }
+
+    static ClassLoader getSystemClassLoader() {
+        return (ClassLoader)
+        AccessController.doPrivileged(new PrivilegedAction() {
+            public Object run() {
+                ClassLoader cl = null;
+                try {
+                    cl = ClassLoader.getSystemClassLoader();
+                } catch (SecurityException ex) {}
+                return cl;
+            }
+        });
+    }
+
+    static ClassLoader getParentClassLoader(final ClassLoader cl) {
+        return (ClassLoader)
+        AccessController.doPrivileged(new PrivilegedAction() {
+            public Object run() {
+                ClassLoader parent = null;
+                try {
+                    parent = cl.getParent();
+                } catch (SecurityException ex) {}
+
+                // eliminate loops in case of the boot
+                // ClassLoader returning itself as a parent
+                return (parent == cl) ? null : parent;
+            }
+        });
+    }
+
+    public static String getSystemProperty(final String propName) {
+        return (String)
+        AccessController.doPrivileged(new PrivilegedAction() {
+            public Object run() {
+                return System.getProperty(propName);
+            }
+        });
+    }
+
+    static FileInputStream getFileInputStream(final File file)
+    throws FileNotFoundException
+    {
+        try {
+            return (FileInputStream)
+            AccessController.doPrivileged(new PrivilegedExceptionAction() {
+                public Object run() throws FileNotFoundException {
+                    return new FileInputStream(file);
+                }
+            });
+        } catch (PrivilegedActionException e) {
+            throw (FileNotFoundException)e.getException();
+        }
+    }
+    /**
+     * Return resource using the same classloader for the ObjectFactory by default
+     * or bootclassloader when Security Manager is in place
+     */
+    public static InputStream getResourceAsStream(final String name) {
+        if (System.getSecurityManager()!=null) {
+            return getResourceAsStream(null, name);
+        } else {
+            return getResourceAsStream(ObjectFactory.findClassLoader(), name);
+        }
+    }
+
+    public static InputStream getResourceAsStream(final ClassLoader cl,
+            final String name)
+    {
+        return (InputStream)
+        AccessController.doPrivileged(new PrivilegedAction() {
+            public Object run() {
+                InputStream ris;
+                if (cl == null) {
+                    ris = Object.class.getResourceAsStream("/"+name);
+                } else {
+                    ris = cl.getResourceAsStream(name);
+                }
+                return ris;
+            }
+        });
+    }
+
+    static boolean getFileExists(final File f) {
+        return ((Boolean)
+                AccessController.doPrivileged(new PrivilegedAction() {
+                    public Object run() {
+                        return f.exists() ? Boolean.TRUE : Boolean.FALSE;
+                    }
+                })).booleanValue();
+    }
+
+    static long getLastModified(final File f) {
+        return ((Long)
+                AccessController.doPrivileged(new PrivilegedAction() {
+                    public Object run() {
+                        return new Long(f.lastModified());
+                    }
+                })).longValue();
+    }
+
+    private SecuritySupport () {}
+}
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xslt/EnvironmentCheck.java	Thu Apr 12 08:38:26 2012 -0700
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xslt/EnvironmentCheck.java	Tue Apr 17 11:17:59 2012 -0700
@@ -22,6 +22,8 @@
  */
 package com.sun.org.apache.xalan.internal.xslt;
 
+import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
+
 import java.io.File;
 import java.io.FileWriter;
 import java.io.PrintWriter;
@@ -794,8 +796,7 @@
     {
       final String JAXP1_CLASS = "javax.xml.stream.XMLStreamConstants";
 
-      clazz = ObjectFactory.findProviderClass(
-        JAXP1_CLASS, ObjectFactory.findClassLoader(), true);
+      clazz = ObjectFactory.findProviderClass(JAXP1_CLASS, true);
 
       // If we succeeded, we have JAXP 1.4 available
       h.put(VERSION + "JAXP", "1.4");
@@ -825,8 +826,7 @@
       final String XALAN1_VERSION_CLASS =
         "com.sun.org.apache.xalan.internal.xslt.XSLProcessorVersion";
 
-      Class clazz = ObjectFactory.findProviderClass(
-        XALAN1_VERSION_CLASS, ObjectFactory.findClassLoader(), true);
+      Class clazz = ObjectFactory.findProviderClass(XALAN1_VERSION_CLASS, true);
 
       // Found Xalan-J 1.x, grab it's version fields
       StringBuffer buf = new StringBuffer();
@@ -858,8 +858,7 @@
       final String XALAN2_VERSION_CLASS =
         "com.sun.org.apache.xalan.internal.processor.XSLProcessorVersion";
 
-      Class clazz = ObjectFactory.findProviderClass(
-        XALAN2_VERSION_CLASS, ObjectFactory.findClassLoader(), true);
+      Class clazz = ObjectFactory.findProviderClass(XALAN2_VERSION_CLASS, true);
 
       // Found Xalan-J 2.x, grab it's version fields
       StringBuffer buf = new StringBuffer();
@@ -880,8 +879,7 @@
       final String XALAN2_2_VERSION_METHOD = "getVersion";
       final Class noArgs[] = new Class[0];
 
-      Class clazz = ObjectFactory.findProviderClass(
-        XALAN2_2_VERSION_CLASS, ObjectFactory.findClassLoader(), true);
+      Class clazz = ObjectFactory.findProviderClass(XALAN2_2_VERSION_CLASS, true);
 
       Method method = clazz.getMethod(XALAN2_2_VERSION_METHOD, noArgs);
       Object returnValue = method.invoke(null, new Object[0]);
@@ -913,8 +911,7 @@
     {
       final String XERCES1_VERSION_CLASS = "com.sun.org.apache.xerces.internal.framework.Version";
 
-      Class clazz = ObjectFactory.findProviderClass(
-        XERCES1_VERSION_CLASS, ObjectFactory.findClassLoader(), true);
+      Class clazz = ObjectFactory.findProviderClass(XERCES1_VERSION_CLASS, true);
 
       // Found Xerces-J 1.x, grab it's version fields
       Field f = clazz.getField("fVersion");
@@ -932,8 +929,7 @@
     {
       final String XERCES2_VERSION_CLASS = "com.sun.org.apache.xerces.internal.impl.Version";
 
-      Class clazz = ObjectFactory.findProviderClass(
-        XERCES2_VERSION_CLASS, ObjectFactory.findClassLoader(), true);
+      Class clazz = ObjectFactory.findProviderClass(XERCES2_VERSION_CLASS, true);
 
       // Found Xerces-J 2.x, grab it's version fields
       Field f = clazz.getField("fVersion");
@@ -950,8 +946,7 @@
     {
       final String CRIMSON_CLASS = "org.apache.crimson.parser.Parser2";
 
-      Class clazz = ObjectFactory.findProviderClass(
-        CRIMSON_CLASS, ObjectFactory.findClassLoader(), true);
+      Class clazz = ObjectFactory.findProviderClass(CRIMSON_CLASS, true);
 
       //@todo determine specific crimson version
       h.put(VERSION + "crimson", CLASS_PRESENT);
@@ -979,8 +974,7 @@
       final String ANT_VERSION_METHOD = "getAntVersion"; // noArgs
       final Class noArgs[] = new Class[0];
 
-      Class clazz = ObjectFactory.findProviderClass(
-        ANT_VERSION_CLASS, ObjectFactory.findClassLoader(), true);
+      Class clazz = ObjectFactory.findProviderClass(ANT_VERSION_CLASS, true);
 
       Method method = clazz.getMethod(ANT_VERSION_METHOD, noArgs);
       Object returnValue = method.invoke(null, new Object[0]);
@@ -1009,8 +1003,7 @@
 
     try
     {
-      Class clazz = ObjectFactory.findProviderClass(
-        DOM_CLASS, ObjectFactory.findClassLoader(), true);
+      Class clazz = ObjectFactory.findProviderClass(DOM_CLASS, true);
 
       Method method = clazz.getMethod(DOM_LEVEL3_METHOD, null);
 
@@ -1052,8 +1045,7 @@
 
     try
     {
-      Class clazz = ObjectFactory.findProviderClass(
-        DOM_LEVEL2_CLASS, ObjectFactory.findClassLoader(), true);
+      Class clazz = ObjectFactory.findProviderClass(DOM_LEVEL2_CLASS, true);
 
       Method method = clazz.getMethod(DOM_LEVEL2_METHOD, twoStringArgs);
 
@@ -1065,8 +1057,7 @@
       {
         // Check for the working draft version, which is
         //  commonly found, but won't work anymore
-        clazz = ObjectFactory.findProviderClass(
-          DOM_LEVEL2WD_CLASS, ObjectFactory.findClassLoader(), true);
+        clazz = ObjectFactory.findProviderClass(DOM_LEVEL2WD_CLASS, true);
 
         method = clazz.getMethod(DOM_LEVEL2WD_METHOD, twoStringArgs);
 
@@ -1078,8 +1069,7 @@
         try
         {
           // Check for the final draft version as well
-          clazz = ObjectFactory.findProviderClass(
-            DOM_LEVEL2FD_CLASS, ObjectFactory.findClassLoader(), true);
+          clazz = ObjectFactory.findProviderClass(DOM_LEVEL2FD_CLASS, true);
 
           method = clazz.getMethod(DOM_LEVEL2FD_METHOD, twoStringArgs);
 
@@ -1133,8 +1123,7 @@
     {
       // This method was only added in the final SAX 2.0 release;
       //  see changes.html "Changes from SAX 2.0beta2 to SAX 2.0prerelease"
-      Class clazz = ObjectFactory.findProviderClass(
-        SAX_VERSION2BETA_CLASSNF, ObjectFactory.findClassLoader(), true);
+      Class clazz = ObjectFactory.findProviderClass(SAX_VERSION2BETA_CLASSNF, true);
 
       Method method = clazz.getMethod(SAX_VERSION2BETA_METHODNF, attributesArg);
 
@@ -1151,8 +1140,7 @@
 
       try
       {
-        Class clazz = ObjectFactory.findProviderClass(
-          SAX_VERSION2_CLASS, ObjectFactory.findClassLoader(), true);
+        Class clazz = ObjectFactory.findProviderClass(SAX_VERSION2_CLASS, true);
 
         Method method = clazz.getMethod(SAX_VERSION2_METHOD, oneStringArg);
 
@@ -1170,8 +1158,7 @@
 
         try
         {
-          Class clazz = ObjectFactory.findProviderClass(
-            SAX_VERSION1_CLASS, ObjectFactory.findClassLoader(), true);
+          Class clazz = ObjectFactory.findProviderClass(SAX_VERSION1_CLASS, true);
 
           Method method = clazz.getMethod(SAX_VERSION1_METHOD, oneStringArg);
 
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xslt/ObjectFactory.java	Thu Apr 12 08:38:26 2012 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,663 +0,0 @@
-/*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
- */
-/*
- * Copyright 2001-2004 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * 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: ObjectFactory.java,v 1.2.4.1 2005/09/12 12:18:06 pvedula Exp $
- */
-
-package com.sun.org.apache.xalan.internal.xslt;
-
-import java.io.InputStream;
-import java.io.IOException;
-import java.io.File;
-import java.io.FileInputStream;
-
-import java.util.Properties;
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
-
-/**
- * This class is duplicated for each JAXP subpackage so keep it in sync.
- * It is package private and therefore is not exposed as part of the JAXP
- * API.
- * <p>
- * This code is designed to implement the JAXP 1.1 spec pluggability
- * feature and is designed to run on JDK version 1.1 and
- * later, and to compile on JDK 1.2 and onward.
- * The code also runs both as part of an unbundled jar file and
- * when bundled as part of the JDK.
- * <p>
- * This class was moved from the <code>javax.xml.parsers.ObjectFactory</code>
- * class and modified to be used as a general utility for creating objects
- * dynamically.
- *
- * @version $Id: ObjectFactory.java,v 1.9 2008/04/02 00:41:00 joehw Exp $
- */
-class ObjectFactory {
-
-    //
-    // Constants
-    //
-
-    // name of default properties file to look for in JDK's jre/lib directory
-    private static final String DEFAULT_PROPERTIES_FILENAME =
-                                                     "xalan.properties";
-
-    private static final String SERVICES_PATH = "META-INF/services/";
-
-    /** Set to true for debugging */
-    private static final boolean DEBUG = false;
-
-    /** cache the contents of the xalan.properties file.
-     *  Until an attempt has been made to read this file, this will
-     * be null; if the file does not exist or we encounter some other error
-     * during the read, this will be empty.
-     */
-    private static Properties fXalanProperties = null;
-
-    /***
-     * Cache the time stamp of the xalan.properties file so
-     * that we know if it's been modified and can invalidate
-     * the cache when necessary.
-     */
-    private static long fLastModified = -1;
-
-    //
-    // Public static methods
-    //
-
-    /**
-     * Finds the implementation Class object in the specified order.  The
-     * specified order is the following:
-     * <ol>
-     *  <li>query the system property using <code>System.getProperty</code>
-     *  <li>read <code>META-INF/services/<i>factoryId</i></code> file
-     *  <li>use fallback classname
-     * </ol>
-     *
-     * @return instance of factory, never null
-     *
-     * @param factoryId             Name of the factory to find, same as
-     *                              a property name
-     * @param fallbackClassName     Implementation class name, if nothing else
-     *                              is found.  Use null to mean no fallback.
-     *
-     * @exception ObjectFactory.ConfigurationError
-     */
-    static Object createObject(String factoryId, String fallbackClassName)
-        throws ConfigurationError {
-        return createObject(factoryId, null, fallbackClassName);
-    } // createObject(String,String):Object
-
-    /**
-     * Finds the implementation Class object in the specified order.  The
-     * specified order is the following:
-     * <ol>
-     *  <li>query the system property using <code>System.getProperty</code>
-     *  <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
-     *  <li>read <code>META-INF/services/<i>factoryId</i></code> file
-     *  <li>use fallback classname
-     * </ol>
-     *
-     * @return instance of factory, never null
-     *
-     * @param factoryId             Name of the factory to find, same as
-     *                              a property name
-     * @param propertiesFilename The filename in the $java.home/lib directory
-     *                           of the properties file.  If none specified,
-     *                           ${java.home}/lib/xalan.properties will be used.
-     * @param fallbackClassName     Implementation class name, if nothing else
-     *                              is found.  Use null to mean no fallback.
-     *
-     * @exception ObjectFactory.ConfigurationError
-     */
-    static Object createObject(String factoryId,
-                                      String propertiesFilename,
-                                      String fallbackClassName)
-        throws ConfigurationError
-    {
-        Class factoryClass = lookUpFactoryClass(factoryId,
-                                                propertiesFilename,
-                                                fallbackClassName);
-
-        if (factoryClass == null) {
-            throw new ConfigurationError(
-                "Provider for " + factoryId + " cannot be found", null);
-        }
-
-        try{
-            Object instance = factoryClass.newInstance();
-            if (DEBUG) debugPrintln("created new instance of factory " + factoryId);
-            return instance;
-        } catch (Exception x) {
-            throw new ConfigurationError(
-                "Provider for factory " + factoryId
-                    + " could not be instantiated: " + x, x);
-        }
-    } // createObject(String,String,String):Object
-
-    /**
-     * Finds the implementation Class object in the specified order.  The
-     * specified order is the following:
-     * <ol>
-     *  <li>query the system property using <code>System.getProperty</code>
-     *  <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
-     *  <li>read <code>META-INF/services/<i>factoryId</i></code> file
-     *  <li>use fallback classname
-     * </ol>
-     *
-     * @return Class object of factory, never null
-     *
-     * @param factoryId             Name of the factory to find, same as
-     *                              a property name
-     * @param propertiesFilename The filename in the $java.home/lib directory
-     *                           of the properties file.  If none specified,
-     *                           ${java.home}/lib/xalan.properties will be used.
-     * @param fallbackClassName     Implementation class name, if nothing else
-     *                              is found.  Use null to mean no fallback.
-     *
-     * @exception ObjectFactory.ConfigurationError
-     */
-    static Class lookUpFactoryClass(String factoryId)
-        throws ConfigurationError
-    {
-        return lookUpFactoryClass(factoryId, null, null);
-    } // lookUpFactoryClass(String):Class
-
-    /**
-     * Finds the implementation Class object in the specified order.  The
-     * specified order is the following:
-     * <ol>
-     *  <li>query the system property using <code>System.getProperty</code>
-     *  <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
-     *  <li>read <code>META-INF/services/<i>factoryId</i></code> file
-     *  <li>use fallback classname
-     * </ol>
-     *
-     * @return Class object that provides factory service, never null
-     *
-     * @param factoryId             Name of the factory to find, same as
-     *                              a property name
-     * @param propertiesFilename The filename in the $java.home/lib directory
-     *                           of the properties file.  If none specified,
-     *                           ${java.home}/lib/xalan.properties will be used.
-     * @param fallbackClassName     Implementation class name, if nothing else
-     *                              is found.  Use null to mean no fallback.
-     *
-     * @exception ObjectFactory.ConfigurationError
-     */
-    static Class lookUpFactoryClass(String factoryId,
-                                           String propertiesFilename,
-                                           String fallbackClassName)
-        throws ConfigurationError
-    {
-        String factoryClassName = lookUpFactoryClassName(factoryId,
-                                                         propertiesFilename,
-                                                         fallbackClassName);
-        ClassLoader cl = findClassLoader();
-
-        if (factoryClassName == null) {
-            factoryClassName = fallbackClassName;
-        }
-
-        // assert(className != null);
-        try{
-            Class providerClass = findProviderClass(factoryClassName,
-                                                    cl,
-                                                    true);
-            if (DEBUG) debugPrintln("created new instance of " + providerClass +
-                   " using ClassLoader: " + cl);
-            return providerClass;
-        } catch (ClassNotFoundException x) {
-            throw new ConfigurationError(
-                "Provider " + factoryClassName + " not found", x);
-        } catch (Exception x) {
-            throw new ConfigurationError(
-                "Provider "+factoryClassName+" could not be instantiated: "+x,
-                x);
-        }
-    } // lookUpFactoryClass(String,String,String):Class
-
-    /**
-     * Finds the name of the required implementation class in the specified
-     * order.  The specified order is the following:
-     * <ol>
-     *  <li>query the system property using <code>System.getProperty</code>
-     *  <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
-     *  <li>read <code>META-INF/services/<i>factoryId</i></code> file
-     *  <li>use fallback classname
-     * </ol>
-     *
-     * @return name of class that provides factory service, never null
-     *
-     * @param factoryId             Name of the factory to find, same as
-     *                              a property name
-     * @param propertiesFilename The filename in the $java.home/lib directory
-     *                           of the properties file.  If none specified,
-     *                           ${java.home}/lib/xalan.properties will be used.
-     * @param fallbackClassName     Implementation class name, if nothing else
-     *                              is found.  Use null to mean no fallback.
-     *
-     * @exception ObjectFactory.ConfigurationError
-     */
-    static String lookUpFactoryClassName(String factoryId,
-                                                String propertiesFilename,
-                                                String fallbackClassName)
-    {
-        SecuritySupport ss = SecuritySupport.getInstance();
-
-        // Use the system property first
-        try {
-            String systemProp = ss.getSystemProperty(factoryId);
-            if (systemProp != null) {
-                if (DEBUG) debugPrintln("found system property, value=" + systemProp);
-                return systemProp;
-            }
-        } catch (SecurityException se) {
-            // Ignore and continue w/ next location
-        }
-
-        // Try to read from propertiesFilename, or
-        // $java.home/lib/xalan.properties
-        String factoryClassName = null;
-        // no properties file name specified; use
-        // $JAVA_HOME/lib/xalan.properties:
-        if (propertiesFilename == null) {
-            File propertiesFile = null;
-            boolean propertiesFileExists = false;
-            try {
-                String javah = ss.getSystemProperty("java.home");
-                propertiesFilename = javah + File.separator +
-                    "lib" + File.separator + DEFAULT_PROPERTIES_FILENAME;
-                propertiesFile = new File(propertiesFilename);
-                propertiesFileExists = ss.getFileExists(propertiesFile);
-            } catch (SecurityException e) {
-                // try again...
-                fLastModified = -1;
-                fXalanProperties = null;
-            }
-
-            synchronized (ObjectFactory.class) {
-                boolean loadProperties = false;
-                FileInputStream fis = null;
-                try {
-                    // file existed last time
-                    if(fLastModified >= 0) {
-                        if(propertiesFileExists &&
-                                (fLastModified < (fLastModified = ss.getLastModified(propertiesFile)))) {
-                            loadProperties = true;
-                        } else {
-                            // file has stopped existing...
-                            if(!propertiesFileExists) {
-                                fLastModified = -1;
-                                fXalanProperties = null;
-                            } // else, file wasn't modified!
-                        }
-                    } else {
-                        // file has started to exist:
-                        if(propertiesFileExists) {
-                            loadProperties = true;
-                            fLastModified = ss.getLastModified(propertiesFile);
-                        } // else, nothing's changed
-                    }
-                    if(loadProperties) {
-                        // must never have attempted to read xalan.properties
-                        // before (or it's outdeated)
-                        fXalanProperties = new Properties();
-                        fis = ss.getFileInputStream(propertiesFile);
-                        fXalanProperties.load(fis);
-                    }
-                } catch (Exception x) {
-                    fXalanProperties = null;
-                    fLastModified = -1;
-                    // assert(x instanceof FileNotFoundException
-                    //        || x instanceof SecurityException)
-                    // In both cases, ignore and continue w/ next location
-                }
-                finally {
-                    // try to close the input stream if one was opened.
-                    if (fis != null) {
-                        try {
-                            fis.close();
-                        }
-                        // Ignore the exception.
-                        catch (IOException exc) {}
-                    }
-                }
-            }
-            if(fXalanProperties != null) {
-                factoryClassName = fXalanProperties.getProperty(factoryId);
-            }
-        } else {
-            FileInputStream fis = null;
-            try {
-                fis = ss.getFileInputStream(new File(propertiesFilename));
-                Properties props = new Properties();
-                props.load(fis);
-                factoryClassName = props.getProperty(factoryId);
-            } catch (Exception x) {
-                // assert(x instanceof FileNotFoundException
-                //        || x instanceof SecurityException)
-                // In both cases, ignore and continue w/ next location
-            }
-            finally {
-                // try to close the input stream if one was opened.
-                if (fis != null) {
-                    try {
-                        fis.close();
-                    }
-                    // Ignore the exception.
-                    catch (IOException exc) {}
-                }
-            }
-        }
-        if (factoryClassName != null) {
-            if (DEBUG) debugPrintln("found in " + propertiesFilename + ", value="
-                          + factoryClassName);
-            return factoryClassName;
-        }
-
-        // Try Jar Service Provider Mechanism
-        return findJarServiceProviderName(factoryId);
-    } // lookUpFactoryClass(String,String):String
-
-    //
-    // Private static methods
-    //
-
-    /** Prints a message to standard error if debugging is enabled. */
-    private static void debugPrintln(String msg) {
-        if (DEBUG) {
-            System.err.println("JAXP: " + msg);
-        }
-    } // debugPrintln(String)
-
-    /**
-     * Figure out which ClassLoader to use.  For JDK 1.2 and later use
-     * the context ClassLoader.
-     */
-    static ClassLoader findClassLoader()
-        throws ConfigurationError
-    {
-        SecuritySupport ss = SecuritySupport.getInstance();
-
-        // Figure out which ClassLoader to use for loading the provider
-        // class.  If there is a Context ClassLoader then use it.
-        ClassLoader context = ss.getContextClassLoader();
-        ClassLoader system = ss.getSystemClassLoader();
-
-        ClassLoader chain = system;
-        while (true) {
-            if (context == chain) {
-                // Assert: we are on JDK 1.1 or we have no Context ClassLoader
-                // or any Context ClassLoader in chain of system classloader
-                // (including extension ClassLoader) so extend to widest
-                // ClassLoader (always look in system ClassLoader if Xalan
-                // is in boot/extension/system classpath and in current
-                // ClassLoader otherwise); normal classloaders delegate
-                // back to system ClassLoader first so this widening doesn't
-                // change the fact that context ClassLoader will be consulted
-                ClassLoader current = ObjectFactory.class.getClassLoader();
-
-                chain = system;
-                while (true) {
-                    if (current == chain) {
-                        // Assert: Current ClassLoader in chain of
-                        // boot/extension/system ClassLoaders
-                        return system;
-                    }
-                    if (chain == null) {
-                        break;
-                    }
-                    chain = ss.getParentClassLoader(chain);
-                }
-
-                // Assert: Current ClassLoader not in chain of
-                // boot/extension/system ClassLoaders
-                return current;
-            }
-
-            if (chain == null) {
-                // boot ClassLoader reached
-                break;
-            }
-
-            // Check for any extension ClassLoaders in chain up to
-            // boot ClassLoader
-            chain = ss.getParentClassLoader(chain);
-        };
-
-        // Assert: Context ClassLoader not in chain of
-        // boot/extension/system ClassLoaders
-        return context;
-    } // findClassLoader():ClassLoader
-
-    /**
-     * Create an instance of a class using the specified ClassLoader
-     */
-    static Object newInstance(String className, ClassLoader cl,
-                                      boolean doFallback)
-        throws ConfigurationError
-    {
-        // assert(className != null);
-        try{
-            Class providerClass = findProviderClass(className, cl, doFallback);
-            Object instance = providerClass.newInstance();
-            if (DEBUG) debugPrintln("created new instance of " + providerClass +
-                   " using ClassLoader: " + cl);
-            return instance;
-        } catch (ClassNotFoundException x) {
-            throw new ConfigurationError(
-                "Provider " + className + " not found", x);
-        } catch (Exception x) {
-            throw new ConfigurationError(
-                "Provider " + className + " could not be instantiated: " + x,
-                x);
-        }
-    }
-
-    /**
-     * Find a Class using the specified ClassLoader
-     */
-    static Class findProviderClass(String className, ClassLoader cl,
-                                           boolean doFallback)
-        throws ClassNotFoundException, ConfigurationError
-    {
-        //throw security exception if the calling thread is not allowed to access the
-        //class. Restrict the access to the package classes as specified in java.security policy.
-        SecurityManager security = System.getSecurityManager();
-        try{
-                if (security != null){
-                    final int lastDot = className.lastIndexOf(".");
-                    String packageName = className;
-                    if (lastDot != -1) packageName = className.substring(0, lastDot);
-                    security.checkPackageAccess(packageName);
-                 }
-        }catch(SecurityException e){
-            throw e;
-        }
-
-        Class providerClass;
-        if (cl == null) {
-            // XXX Use the bootstrap ClassLoader.  There is no way to
-            // load a class using the bootstrap ClassLoader that works
-            // in both JDK 1.1 and Java 2.  However, this should still
-            // work b/c the following should be true:
-            //
-            // (cl == null) iff current ClassLoader == null
-            //
-            // Thus Class.forName(String) will use the current
-            // ClassLoader which will be the bootstrap ClassLoader.
-            providerClass = Class.forName(className);
-        } else {
-            try {
-                providerClass = cl.loadClass(className);
-            } catch (ClassNotFoundException x) {
-                if (doFallback) {
-                    // Fall back to current classloader
-                    ClassLoader current = ObjectFactory.class.getClassLoader();
-                    if (current == null) {
-                        providerClass = Class.forName(className);
-                    } else if (cl != current) {
-                        cl = current;
-                        providerClass = cl.loadClass(className);
-                    } else {
-                        throw x;
-                    }
-                } else {
-                    throw x;
-                }
-            }
-        }
-
-        return providerClass;
-    }
-
-    /**
-     * Find the name of service provider using Jar Service Provider Mechanism
-     *
-     * @return instance of provider class if found or null
-     */
-    private static String findJarServiceProviderName(String factoryId)
-    {
-        SecuritySupport ss = SecuritySupport.getInstance();
-        String serviceId = SERVICES_PATH + factoryId;
-        InputStream is = null;
-
-        // First try the Context ClassLoader
-        ClassLoader cl = findClassLoader();
-
-        is = ss.getResourceAsStream(cl, serviceId);
-
-        // If no provider found then try the current ClassLoader
-        if (is == null) {
-            ClassLoader current = ObjectFactory.class.getClassLoader();
-            if (cl != current) {
-                cl = current;
-                is = ss.getResourceAsStream(cl, serviceId);
-            }
-        }
-
-        if (is == null) {
-            // No provider found
-            return null;
-        }
-
-        if (DEBUG) debugPrintln("found jar resource=" + serviceId +
-               " using ClassLoader: " + cl);
-
-        // Read the service provider name in UTF-8 as specified in
-        // the jar spec.  Unfortunately this fails in Microsoft
-        // VJ++, which does not implement the UTF-8
-        // encoding. Theoretically, we should simply let it fail in
-        // that case, since the JVM is obviously broken if it
-        // doesn't support such a basic standard.  But since there
-        // are still some users attempting to use VJ++ for
-        // development, we have dropped in a fallback which makes a
-        // second attempt using the platform's default encoding. In
-        // VJ++ this is apparently ASCII, which is a subset of
-        // UTF-8... and since the strings we'll be reading here are
-        // also primarily limited to the 7-bit ASCII range (at
-        // least, in English versions), this should work well
-        // enough to keep us on the air until we're ready to
-        // officially decommit from VJ++. [Edited comment from
-        // jkesselm]
-        BufferedReader rd;
-        try {
-            rd = new BufferedReader(new InputStreamReader(is, "UTF-8"));
-        } catch (java.io.UnsupportedEncodingException e) {
-            rd = new BufferedReader(new InputStreamReader(is));
-        }
-
-        String factoryClassName = null;
-        try {
-            // XXX Does not handle all possible input as specified by the
-            // Jar Service Provider specification
-            factoryClassName = rd.readLine();
-        } catch (IOException x) {
-            // No provider found
-            return null;
-        }
-        finally {
-            try {
-                // try to close the reader.
-                rd.close();
-            }
-            // Ignore the exception.
-            catch (IOException exc) {}
-        }
-
-        if (factoryClassName != null &&
-            ! "".equals(factoryClassName)) {
-            if (DEBUG) debugPrintln("found in resource, value="
-                   + factoryClassName);
-
-            // Note: here we do not want to fall back to the current
-            // ClassLoader because we want to avoid the case where the
-            // resource file was found using one ClassLoader and the
-            // provider class was instantiated using a different one.
-            return factoryClassName;
-        }
-
-        // No provider found
-        return null;
-    }
-
-    //
-    // Classes
-    //
-
-    /**
-     * A configuration error.
-     */
-    static class ConfigurationError
-        extends Error {
-                static final long serialVersionUID = 2276082712114762609L;
-        //
-        // Data
-        //
-
-        /** Exception. */
-        private Exception exception;
-
-        //
-        // Constructors
-        //
-
-        /**
-         * Construct a new instance with the specified detail string and
-         * exception.
-         */
-        ConfigurationError(String msg, Exception x) {
-            super(msg);
-            this.exception = x;
-        } // <init>(String,Exception)
-
-        //
-        // Public methods
-        //
-
-        /** Returns the exception associated to this error. */
-        Exception getException() {
-            return exception;
-        } // getException():Exception
-
-    } // class ConfigurationError
-
-} // class ObjectFactory
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xslt/Process.java	Thu Apr 12 08:38:26 2012 -0700
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xslt/Process.java	Tue Apr 17 11:17:59 2012 -0700
@@ -55,6 +55,8 @@
 import com.sun.org.apache.xalan.internal.Version;
 import com.sun.org.apache.xalan.internal.res.XSLMessages;
 import com.sun.org.apache.xalan.internal.res.XSLTErrorResources;
+import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
+import com.sun.org.apache.xalan.internal.utils.ConfigurationError;
 
 //J2SE does not support Xalan interpretive
 /*
@@ -457,12 +459,11 @@
           {
             try
             {
-              uriResolver = (URIResolver) ObjectFactory.newInstance(
-                argv[++i], ObjectFactory.findClassLoader(), true);
+              uriResolver = (URIResolver) ObjectFactory.newInstance(argv[++i], true);
 
               tfactory.setURIResolver(uriResolver);
             }
-            catch (ObjectFactory.ConfigurationError cnfe)
+            catch (ConfigurationError cnfe)
             {
                 msg = XSLMessages.createMessage(
                     XSLTErrorResources.ER_CLASS_NOT_FOUND_FOR_OPTION,
@@ -486,10 +487,9 @@
           {
             try
             {
-              entityResolver = (EntityResolver) ObjectFactory.newInstance(
-                argv[++i], ObjectFactory.findClassLoader(), true);
+              entityResolver = (EntityResolver) ObjectFactory.newInstance(argv[++i], true);
             }
-            catch (ObjectFactory.ConfigurationError cnfe)
+            catch (ConfigurationError cnfe)
             {
                 msg = XSLMessages.createMessage(
                     XSLTErrorResources.ER_CLASS_NOT_FOUND_FOR_OPTION,
@@ -514,10 +514,9 @@
           {
             try
             {
-              contentHandler = (ContentHandler) ObjectFactory.newInstance(
-                argv[++i], ObjectFactory.findClassLoader(), true);
+              contentHandler = (ContentHandler) ObjectFactory.newInstance(argv[++i], true);
             }
-            catch (ObjectFactory.ConfigurationError cnfe)
+            catch (ConfigurationError cnfe)
             {
                 msg = XSLMessages.createMessage(
                     XSLTErrorResources.ER_CLASS_NOT_FOUND_FOR_OPTION,
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xslt/SecuritySupport.java	Thu Apr 12 08:38:26 2012 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,127 +0,0 @@
-/*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
- */
-/*
- * Copyright 2002-2004 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * 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: SecuritySupport.java,v 1.2.4.1 2005/09/09 07:17:15 pvedula Exp $
- */
-
-package com.sun.org.apache.xalan.internal.xslt;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.InputStream;
-
-import java.util.Properties;
-
-/**
- * This class is duplicated for each Xalan-Java subpackage so keep it in sync.
- * It is package private and therefore is not exposed as part of the Xalan-Java
- * API.
- *
- * Base class with security related methods that work on JDK 1.1.
- */
-class SecuritySupport {
-
-    /*
-     * Make this of type Object so that the verifier won't try to
-     * prove its type, thus possibly trying to load the SecuritySupport12
-     * class.
-     */
-    private static final Object securitySupport;
-
-    static {
-        SecuritySupport ss = null;
-        try {
-            Class c = Class.forName("java.security.AccessController");
-            // if that worked, we're on 1.2.
-            /*
-            // don't reference the class explicitly so it doesn't
-            // get dragged in accidentally.
-            c = Class.forName("javax.mail.SecuritySupport12");
-            Constructor cons = c.getConstructor(new Class[] { });
-            ss = (SecuritySupport)cons.newInstance(new Object[] { });
-            */
-            /*
-             * Unfortunately, we can't load the class using reflection
-             * because the class is package private.  And the class has
-             * to be package private so the APIs aren't exposed to other
-             * code that could use them to circumvent security.  Thus,
-             * we accept the risk that the direct reference might fail
-             * on some JDK 1.1 JVMs, even though we would never execute
-             * this code in such a case.  Sigh...
-             */
-            ss = new SecuritySupport12();
-        } catch (Exception ex) {
-            // ignore it
-        } finally {
-            if (ss == null)
-                ss = new SecuritySupport();
-            securitySupport = ss;
-        }
-    }
-
-    /**
-     * Return an appropriate instance of this class, depending on whether
-     * we're on a JDK 1.1 or J2SE 1.2 (or later) system.
-     */
-    static SecuritySupport getInstance() {
-        return (SecuritySupport)securitySupport;
-    }
-
-    ClassLoader getContextClassLoader() {
-        return null;
-    }
-
-    ClassLoader getSystemClassLoader() {
-        return null;
-    }
-
-    ClassLoader getParentClassLoader(ClassLoader cl) {
-        return null;
-    }
-
-    String getSystemProperty(String propName) {
-        return System.getProperty(propName);
-    }
-
-    FileInputStream getFileInputStream(File file)
-        throws FileNotFoundException
-    {
-        return new FileInputStream(file);
-    }
-
-    InputStream getResourceAsStream(ClassLoader cl, String name) {
-        InputStream ris;
-        if (cl == null) {
-            ris = ClassLoader.getSystemResourceAsStream(name);
-        } else {
-            ris = cl.getResourceAsStream(name);
-        }
-        return ris;
-    }
-
-    boolean getFileExists(File f) {
-        return f.exists();
-    }
-
-    long getLastModified(File f) {
-        return f.lastModified();
-    }
-}
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xslt/SecuritySupport12.java	Thu Apr 12 08:38:26 2012 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,148 +0,0 @@
-/*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
- */
-/*
- * Copyright 2002-2004 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * 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: SecuritySupport12.java,v 1.2.4.1 2005/09/09 07:17:45 pvedula Exp $
- */
-
-package com.sun.org.apache.xalan.internal.xslt;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.InputStream;
-
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
-
-import java.util.Properties;
-
-/**
- * This class is duplicated for each Xalan-Java subpackage so keep it in sync.
- * It is package private and therefore is not exposed as part of the Xalan-Java
- * API.
- *
- * Security related methods that only work on J2SE 1.2 and newer.
- */
-class SecuritySupport12 extends SecuritySupport {
-
-    ClassLoader getContextClassLoader() {
-        return (ClassLoader)
-                AccessController.doPrivileged(new PrivilegedAction() {
-            public Object run() {
-                ClassLoader cl = null;
-                try {
-                    cl = Thread.currentThread().getContextClassLoader();
-                } catch (SecurityException ex) { }
-                return cl;
-            }
-        });
-    }
-
-    ClassLoader getSystemClassLoader() {
-        return (ClassLoader)
-            AccessController.doPrivileged(new PrivilegedAction() {
-                public Object run() {
-                    ClassLoader cl = null;
-                    try {
-                        cl = ClassLoader.getSystemClassLoader();
-                    } catch (SecurityException ex) {}
-                    return cl;
-                }
-            });
-    }
-
-    ClassLoader getParentClassLoader(final ClassLoader cl) {
-        return (ClassLoader)
-            AccessController.doPrivileged(new PrivilegedAction() {
-                public Object run() {
-                    ClassLoader parent = null;
-                    try {
-                        parent = cl.getParent();
-                    } catch (SecurityException ex) {}
-
-                    // eliminate loops in case of the boot
-                    // ClassLoader returning itself as a parent
-                    return (parent == cl) ? null : parent;
-                }
-            });
-    }
-
-    String getSystemProperty(final String propName) {
-        return (String)
-            AccessController.doPrivileged(new PrivilegedAction() {
-                public Object run() {
-                    return System.getProperty(propName);
-                }
-            });
-    }
-
-    FileInputStream getFileInputStream(final File file)
-        throws FileNotFoundException
-    {
-        try {
-            return (FileInputStream)
-                AccessController.doPrivileged(new PrivilegedExceptionAction() {
-                    public Object run() throws FileNotFoundException {
-                        return new FileInputStream(file);
-                    }
-                });
-        } catch (PrivilegedActionException e) {
-            throw (FileNotFoundException)e.getException();
-        }
-    }
-
-    InputStream getResourceAsStream(final ClassLoader cl,
-                                           final String name)
-    {
-        return (InputStream)
-            AccessController.doPrivileged(new PrivilegedAction() {
-                public Object run() {
-                    InputStream ris;
-                    if (cl == null) {
-                        ris = ClassLoader.getSystemResourceAsStream(name);
-                    } else {
-                        ris = cl.getResourceAsStream(name);
-                    }
-                    return ris;
-                }
-            });
-    }
-
-    boolean getFileExists(final File f) {
-    return ((Boolean)
-            AccessController.doPrivileged(new PrivilegedAction() {
-                public Object run() {
-                    return new Boolean(f.exists());
-                }
-            })).booleanValue();
-    }
-
-    long getLastModified(final File f) {
-    return ((Long)
-            AccessController.doPrivileged(new PrivilegedAction() {
-                public Object run() {
-                    return new Long(f.lastModified());
-                }
-            })).longValue();
-    }
-
-}
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/Translet.java	Thu Apr 12 08:38:26 2012 -0700
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/Translet.java	Tue Apr 17 11:17:59 2012 -0700
@@ -51,4 +51,7 @@
     public String[] getUrisArray();
     public int[]    getTypesArray();
     public String[] getNamespaceArray();
+    public boolean useServicesMechnism();
+    public void setServicesMechnism(boolean flag);
+
 }
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/cmdline/Compile.java	Thu Apr 12 08:38:26 2012 -0700
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/cmdline/Compile.java	Tue Apr 17 11:17:59 2012 -0700
@@ -55,11 +55,10 @@
 
 
     public static void printUsage() {
-        StringBuffer vers = new StringBuffer("XSLTC version " +
-            VERSION_MAJOR + "." + VERSION_MINOR +
-            ((VERSION_DELTA > 0) ? ("."+VERSION_DELTA) : ("")));
-        System.err.println(vers + "\n" +
-                new ErrorMsg(ErrorMsg.COMPILE_USAGE_STR));
+      System.err.println("XSLTC version " +
+              VERSION_MAJOR + "." + VERSION_MINOR +
+              ((VERSION_DELTA > 0) ? ("." + VERSION_DELTA) : ("")) + "\n" +
+              new ErrorMsg(ErrorMsg.COMPILE_USAGE_STR));
         if (_allowExit) System.exit(-1);
     }
 
@@ -78,7 +77,7 @@
             final GetOpt getopt = new GetOpt(args, "o:d:j:p:uxhsinv");
             if (args.length < 1) printUsage();
 
-            final XSLTC xsltc = new XSLTC();
+            final XSLTC xsltc = new XSLTC(true);
             xsltc.init();
 
             int c;
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/cmdline/ObjectFactory.java	Thu Apr 12 08:38:26 2012 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,663 +0,0 @@
-/*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
- */
-/*
- * Copyright 2001-2004 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * 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: ObjectFactory.java,v 1.2.4.1 2005/09/12 09:12:02 pvedula Exp $
- */
-
-package com.sun.org.apache.xalan.internal.xsltc.cmdline;
-
-import java.io.InputStream;
-import java.io.IOException;
-import java.io.File;
-import java.io.FileInputStream;
-
-import java.util.Properties;
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
-
-/**
- * This class is duplicated for each JAXP subpackage so keep it in sync.
- * It is package private and therefore is not exposed as part of the JAXP
- * API.
- * <p>
- * This code is designed to implement the JAXP 1.1 spec pluggability
- * feature and is designed to run on JDK version 1.1 and
- * later, and to compile on JDK 1.2 and onward.
- * The code also runs both as part of an unbundled jar file and
- * when bundled as part of the JDK.
- * <p>
- * This class was moved from the <code>javax.xml.parsers.ObjectFactory</code>
- * class and modified to be used as a general utility for creating objects
- * dynamically.
- *
- * @version $Id: ObjectFactory.java,v 1.9 2008/04/02 00:41:02 joehw Exp $
- */
-class ObjectFactory {
-
-    //
-    // Constants
-    //
-
-    // name of default properties file to look for in JDK's jre/lib directory
-    private static final String DEFAULT_PROPERTIES_FILENAME =
-                                                     "xalan.properties";
-
-    private static final String SERVICES_PATH = "META-INF/services/";
-
-    /** Set to true for debugging */
-    private static final boolean DEBUG = false;
-
-    /** cache the contents of the xalan.properties file.
-     *  Until an attempt has been made to read this file, this will
-     * be null; if the file does not exist or we encounter some other error
-     * during the read, this will be empty.
-     */
-    private static Properties fXalanProperties = null;
-
-    /***
-     * Cache the time stamp of the xalan.properties file so
-     * that we know if it's been modified and can invalidate
-     * the cache when necessary.
-     */
-    private static long fLastModified = -1;
-
-    //
-    // Public static methods
-    //
-
-    /**
-     * Finds the implementation Class object in the specified order.  The
-     * specified order is the following:
-     * <ol>
-     *  <li>query the system property using <code>System.getProperty</code>
-     *  <li>read <code>META-INF/services/<i>factoryId</i></code> file
-     *  <li>use fallback classname
-     * </ol>
-     *
-     * @return instance of factory, never null
-     *
-     * @param factoryId             Name of the factory to find, same as
-     *                              a property name
-     * @param fallbackClassName     Implementation class name, if nothing else
-     *                              is found.  Use null to mean no fallback.
-     *
-     * @exception ObjectFactory.ConfigurationError
-     */
-    static Object createObject(String factoryId, String fallbackClassName)
-        throws ConfigurationError {
-        return createObject(factoryId, null, fallbackClassName);
-    } // createObject(String,String):Object
-
-    /**
-     * Finds the implementation Class object in the specified order.  The
-     * specified order is the following:
-     * <ol>
-     *  <li>query the system property using <code>System.getProperty</code>
-     *  <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
-     *  <li>read <code>META-INF/services/<i>factoryId</i></code> file
-     *  <li>use fallback classname
-     * </ol>
-     *
-     * @return instance of factory, never null
-     *
-     * @param factoryId             Name of the factory to find, same as
-     *                              a property name
-     * @param propertiesFilename The filename in the $java.home/lib directory
-     *                           of the properties file.  If none specified,
-     *                           ${java.home}/lib/xalan.properties will be used.
-     * @param fallbackClassName     Implementation class name, if nothing else
-     *                              is found.  Use null to mean no fallback.
-     *
-     * @exception ObjectFactory.ConfigurationError
-     */
-    static Object createObject(String factoryId,
-                                      String propertiesFilename,
-                                      String fallbackClassName)
-        throws ConfigurationError
-    {
-        Class factoryClass = lookUpFactoryClass(factoryId,
-                                                propertiesFilename,
-                                                fallbackClassName);
-
-        if (factoryClass == null) {
-            throw new ConfigurationError(
-                "Provider for " + factoryId + " cannot be found", null);
-        }
-
-        try{
-            Object instance = factoryClass.newInstance();
-            if (DEBUG) debugPrintln("created new instance of factory " + factoryId);
-            return instance;
-        } catch (Exception x) {
-            throw new ConfigurationError(
-                "Provider for factory " + factoryId
-                    + " could not be instantiated: " + x, x);
-        }
-    } // createObject(String,String,String):Object
-
-    /**
-     * Finds the implementation Class object in the specified order.  The
-     * specified order is the following:
-     * <ol>
-     *  <li>query the system property using <code>System.getProperty</code>
-     *  <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
-     *  <li>read <code>META-INF/services/<i>factoryId</i></code> file
-     *  <li>use fallback classname
-     * </ol>
-     *
-     * @return Class object of factory, never null
-     *
-     * @param factoryId             Name of the factory to find, same as
-     *                              a property name
-     * @param propertiesFilename The filename in the $java.home/lib directory
-     *                           of the properties file.  If none specified,
-     *                           ${java.home}/lib/xalan.properties will be used.
-     * @param fallbackClassName     Implementation class name, if nothing else
-     *                              is found.  Use null to mean no fallback.
-     *
-     * @exception ObjectFactory.ConfigurationError
-     */
-    static Class lookUpFactoryClass(String factoryId)
-        throws ConfigurationError
-    {
-        return lookUpFactoryClass(factoryId, null, null);
-    } // lookUpFactoryClass(String):Class
-
-    /**
-     * Finds the implementation Class object in the specified order.  The
-     * specified order is the following:
-     * <ol>
-     *  <li>query the system property using <code>System.getProperty</code>
-     *  <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
-     *  <li>read <code>META-INF/services/<i>factoryId</i></code> file
-     *  <li>use fallback classname
-     * </ol>
-     *
-     * @return Class object that provides factory service, never null
-     *
-     * @param factoryId             Name of the factory to find, same as
-     *                              a property name
-     * @param propertiesFilename The filename in the $java.home/lib directory
-     *                           of the properties file.  If none specified,
-     *                           ${java.home}/lib/xalan.properties will be used.
-     * @param fallbackClassName     Implementation class name, if nothing else
-     *                              is found.  Use null to mean no fallback.
-     *
-     * @exception ObjectFactory.ConfigurationError
-     */
-    static Class lookUpFactoryClass(String factoryId,
-                                           String propertiesFilename,
-                                           String fallbackClassName)
-        throws ConfigurationError
-    {
-        String factoryClassName = lookUpFactoryClassName(factoryId,
-                                                         propertiesFilename,
-                                                         fallbackClassName);
-        ClassLoader cl = findClassLoader();
-
-        if (factoryClassName == null) {
-            factoryClassName = fallbackClassName;
-        }
-
-        // assert(className != null);
-        try{
-            Class providerClass = findProviderClass(factoryClassName,
-                                                    cl,
-                                                    true);
-            if (DEBUG) debugPrintln("created new instance of " + providerClass +
-                   " using ClassLoader: " + cl);
-            return providerClass;
-        } catch (ClassNotFoundException x) {
-            throw new ConfigurationError(
-                "Provider " + factoryClassName + " not found", x);
-        } catch (Exception x) {
-            throw new ConfigurationError(
-                "Provider "+factoryClassName+" could not be instantiated: "+x,
-                x);
-        }
-    } // lookUpFactoryClass(String,String,String):Class
-
-    /**
-     * Finds the name of the required implementation class in the specified
-     * order.  The specified order is the following:
-     * <ol>
-     *  <li>query the system property using <code>System.getProperty</code>
-     *  <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
-     *  <li>read <code>META-INF/services/<i>factoryId</i></code> file
-     *  <li>use fallback classname
-     * </ol>
-     *
-     * @return name of class that provides factory service, never null
-     *
-     * @param factoryId             Name of the factory to find, same as
-     *                              a property name
-     * @param propertiesFilename The filename in the $java.home/lib directory
-     *                           of the properties file.  If none specified,
-     *                           ${java.home}/lib/xalan.properties will be used.
-     * @param fallbackClassName     Implementation class name, if nothing else
-     *                              is found.  Use null to mean no fallback.
-     *
-     * @exception ObjectFactory.ConfigurationError
-     */
-    static String lookUpFactoryClassName(String factoryId,
-                                                String propertiesFilename,
-                                                String fallbackClassName)
-    {
-        SecuritySupport ss = SecuritySupport.getInstance();
-
-        // Use the system property first
-        try {
-            String systemProp = ss.getSystemProperty(factoryId);
-            if (systemProp != null) {
-                if (DEBUG) debugPrintln("found system property, value=" + systemProp);
-                return systemProp;
-            }
-        } catch (SecurityException se) {
-            // Ignore and continue w/ next location
-        }
-
-        // Try to read from propertiesFilename, or
-        // $java.home/lib/xalan.properties
-        String factoryClassName = null;
-        // no properties file name specified; use
-        // $JAVA_HOME/lib/xalan.properties:
-        if (propertiesFilename == null) {
-            File propertiesFile = null;
-            boolean propertiesFileExists = false;
-            try {
-                String javah = ss.getSystemProperty("java.home");
-                propertiesFilename = javah + File.separator +
-                    "lib" + File.separator + DEFAULT_PROPERTIES_FILENAME;
-                propertiesFile = new File(propertiesFilename);
-                propertiesFileExists = ss.getFileExists(propertiesFile);
-            } catch (SecurityException e) {
-                // try again...
-                fLastModified = -1;
-                fXalanProperties = null;
-            }
-
-            synchronized (ObjectFactory.class) {
-                boolean loadProperties = false;
-                FileInputStream fis = null;
-                try {
-                    // file existed last time
-                    if(fLastModified >= 0) {
-                        if(propertiesFileExists &&
-                                (fLastModified < (fLastModified = ss.getLastModified(propertiesFile)))) {
-                            loadProperties = true;
-                        } else {
-                            // file has stopped existing...
-                            if(!propertiesFileExists) {
-                                fLastModified = -1;
-                                fXalanProperties = null;
-                            } // else, file wasn't modified!
-                        }
-                    } else {
-                        // file has started to exist:
-                        if(propertiesFileExists) {
-                            loadProperties = true;
-                            fLastModified = ss.getLastModified(propertiesFile);
-                        } // else, nothing's changed
-                    }
-                    if(loadProperties) {
-                        // must never have attempted to read xalan.properties
-                        // before (or it's outdeated)
-                        fXalanProperties = new Properties();
-                        fis = ss.getFileInputStream(propertiesFile);
-                        fXalanProperties.load(fis);
-                    }
-                } catch (Exception x) {
-                    fXalanProperties = null;
-                    fLastModified = -1;
-                    // assert(x instanceof FileNotFoundException
-                    //        || x instanceof SecurityException)
-                    // In both cases, ignore and continue w/ next location
-                }
-                finally {
-                    // try to close the input stream if one was opened.
-                    if (fis != null) {
-                        try {
-                            fis.close();
-                        }
-                        // Ignore the exception.
-                        catch (IOException exc) {}
-                    }
-                }
-            }
-            if(fXalanProperties != null) {
-                factoryClassName = fXalanProperties.getProperty(factoryId);
-            }
-        } else {
-            FileInputStream fis = null;
-            try {
-                fis = ss.getFileInputStream(new File(propertiesFilename));
-                Properties props = new Properties();
-                props.load(fis);
-                factoryClassName = props.getProperty(factoryId);
-            } catch (Exception x) {
-                // assert(x instanceof FileNotFoundException
-                //        || x instanceof SecurityException)
-                // In both cases, ignore and continue w/ next location
-            }
-            finally {
-                // try to close the input stream if one was opened.
-                if (fis != null) {
-                    try {
-                        fis.close();
-                    }
-                    // Ignore the exception.
-                    catch (IOException exc) {}
-                }
-            }
-        }
-        if (factoryClassName != null) {
-            if (DEBUG) debugPrintln("found in " + propertiesFilename + ", value="
-                          + factoryClassName);
-            return factoryClassName;
-        }
-
-        // Try Jar Service Provider Mechanism
-        return findJarServiceProviderName(factoryId);
-    } // lookUpFactoryClass(String,String):String
-
-    //
-    // Private static methods
-    //
-
-    /** Prints a message to standard error if debugging is enabled. */
-    private static void debugPrintln(String msg) {
-        if (DEBUG) {
-            System.err.println("JAXP: " + msg);
-        }
-    } // debugPrintln(String)
-
-    /**
-     * Figure out which ClassLoader to use.  For JDK 1.2 and later use
-     * the context ClassLoader.
-     */
-    static ClassLoader findClassLoader()
-        throws ConfigurationError
-    {
-        SecuritySupport ss = SecuritySupport.getInstance();
-
-        // Figure out which ClassLoader to use for loading the provider
-        // class.  If there is a Context ClassLoader then use it.
-        ClassLoader context = ss.getContextClassLoader();
-        ClassLoader system = ss.getSystemClassLoader();
-
-        ClassLoader chain = system;
-        while (true) {
-            if (context == chain) {
-                // Assert: we are on JDK 1.1 or we have no Context ClassLoader
-                // or any Context ClassLoader in chain of system classloader
-                // (including extension ClassLoader) so extend to widest
-                // ClassLoader (always look in system ClassLoader if Xalan
-                // is in boot/extension/system classpath and in current
-                // ClassLoader otherwise); normal classloaders delegate
-                // back to system ClassLoader first so this widening doesn't
-                // change the fact that context ClassLoader will be consulted
-                ClassLoader current = ObjectFactory.class.getClassLoader();
-
-                chain = system;
-                while (true) {
-                    if (current == chain) {
-                        // Assert: Current ClassLoader in chain of
-                        // boot/extension/system ClassLoaders
-                        return system;
-                    }
-                    if (chain == null) {
-                        break;
-                    }
-                    chain = ss.getParentClassLoader(chain);
-                }
-
-                // Assert: Current ClassLoader not in chain of
-                // boot/extension/system ClassLoaders
-                return current;
-            }
-
-            if (chain == null) {
-                // boot ClassLoader reached
-                break;
-            }
-
-            // Check for any extension ClassLoaders in chain up to
-            // boot ClassLoader
-            chain = ss.getParentClassLoader(chain);
-        };
-
-        // Assert: Context ClassLoader not in chain of
-        // boot/extension/system ClassLoaders
-        return context;
-    } // findClassLoader():ClassLoader
-
-    /**
-     * Create an instance of a class using the specified ClassLoader
-     */
-    static Object newInstance(String className, ClassLoader cl,
-                                      boolean doFallback)
-        throws ConfigurationError
-    {
-        // assert(className != null);
-        try{
-            Class providerClass = findProviderClass(className, cl, doFallback);
-            Object instance = providerClass.newInstance();
-            if (DEBUG) debugPrintln("created new instance of " + providerClass +
-                   " using ClassLoader: " + cl);
-            return instance;
-        } catch (ClassNotFoundException x) {
-            throw new ConfigurationError(
-                "Provider " + className + " not found", x);
-        } catch (Exception x) {
-            throw new ConfigurationError(
-                "Provider " + className + " could not be instantiated: " + x,
-                x);
-        }
-    }
-
-    /**
-     * Find a Class using the specified ClassLoader
-     */
-    static Class findProviderClass(String className, ClassLoader cl,
-                                           boolean doFallback)
-        throws ClassNotFoundException, ConfigurationError
-    {
-        //throw security exception if the calling thread is not allowed to access the
-        //class. Restrict the access to the package classes as specified in java.security policy.
-        SecurityManager security = System.getSecurityManager();
-        try{
-                if (security != null){
-                    final int lastDot = className.lastIndexOf(".");
-                    String packageName = className;
-                    if (lastDot != -1) packageName = className.substring(0, lastDot);
-                    security.checkPackageAccess(packageName);
-                 }
-        }catch(SecurityException e){
-            throw e;
-        }
-
-        Class providerClass;
-        if (cl == null) {
-            // XXX Use the bootstrap ClassLoader.  There is no way to
-            // load a class using the bootstrap ClassLoader that works
-            // in both JDK 1.1 and Java 2.  However, this should still
-            // work b/c the following should be true:
-            //
-            // (cl == null) iff current ClassLoader == null
-            //
-            // Thus Class.forName(String) will use the current
-            // ClassLoader which will be the bootstrap ClassLoader.
-            providerClass = Class.forName(className);
-        } else {
-            try {
-                providerClass = cl.loadClass(className);
-            } catch (ClassNotFoundException x) {
-                if (doFallback) {
-                    // Fall back to current classloader
-                    ClassLoader current = ObjectFactory.class.getClassLoader();
-                    if (current == null) {
-                        providerClass = Class.forName(className);
-                    } else if (cl != current) {
-                        cl = current;
-                        providerClass = cl.loadClass(className);
-                    } else {
-                        throw x;
-                    }
-                } else {
-                    throw x;
-                }
-            }
-        }
-
-        return providerClass;
-    }
-
-    /**
-     * Find the name of service provider using Jar Service Provider Mechanism
-     *
-     * @return instance of provider class if found or null
-     */
-    private static String findJarServiceProviderName(String factoryId)
-    {
-        SecuritySupport ss = SecuritySupport.getInstance();
-        String serviceId = SERVICES_PATH + factoryId;
-        InputStream is = null;
-
-        // First try the Context ClassLoader
-        ClassLoader cl = findClassLoader();
-
-        is = ss.getResourceAsStream(cl, serviceId);
-
-        // If no provider found then try the current ClassLoader
-        if (is == null) {
-            ClassLoader current = ObjectFactory.class.getClassLoader();
-            if (cl != current) {
-                cl = current;
-                is = ss.getResourceAsStream(cl, serviceId);
-            }
-        }
-
-        if (is == null) {
-            // No provider found
-            return null;
-        }
-
-        if (DEBUG) debugPrintln("found jar resource=" + serviceId +
-               " using ClassLoader: " + cl);
-
-        // Read the service provider name in UTF-8 as specified in
-        // the jar spec.  Unfortunately this fails in Microsoft
-        // VJ++, which does not implement the UTF-8
-        // encoding. Theoretically, we should simply let it fail in
-        // that case, since the JVM is obviously broken if it
-        // doesn't support such a basic standard.  But since there
-        // are still some users attempting to use VJ++ for
-        // development, we have dropped in a fallback which makes a
-        // second attempt using the platform's default encoding. In
-        // VJ++ this is apparently ASCII, which is a subset of
-        // UTF-8... and since the strings we'll be reading here are
-        // also primarily limited to the 7-bit ASCII range (at
-        // least, in English versions), this should work well
-        // enough to keep us on the air until we're ready to
-        // officially decommit from VJ++. [Edited comment from
-        // jkesselm]
-        BufferedReader rd;
-        try {
-            rd = new BufferedReader(new InputStreamReader(is, "UTF-8"));
-        } catch (java.io.UnsupportedEncodingException e) {
-            rd = new BufferedReader(new InputStreamReader(is));
-        }
-
-        String factoryClassName = null;
-        try {
-            // XXX Does not handle all possible input as specified by the
-            // Jar Service Provider specification
-            factoryClassName = rd.readLine();
-        } catch (IOException x) {
-            // No provider found
-            return null;
-        }
-        finally {
-            try {
-                // try to close the reader.
-                rd.close();
-            }
-            // Ignore the exception.
-            catch (IOException exc) {}
-        }
-
-        if (factoryClassName != null &&
-            ! "".equals(factoryClassName)) {
-            if (DEBUG) debugPrintln("found in resource, value="
-                   + factoryClassName);
-
-            // Note: here we do not want to fall back to the current
-            // ClassLoader because we want to avoid the case where the
-            // resource file was found using one ClassLoader and the
-            // provider class was instantiated using a different one.
-            return factoryClassName;
-        }
-
-        // No provider found
-        return null;
-    }
-
-    //
-    // Classes
-    //
-
-    /**
-     * A configuration error.
-     */
-    static class ConfigurationError
-        extends Error {
-                static final long serialVersionUID = -6072257854297546607L;
-        //
-        // Data
-        //
-
-        /** Exception. */
-        private Exception exception;
-
-        //
-        // Constructors
-        //
-
-        /**
-         * Construct a new instance with the specified detail string and
-         * exception.
-         */
-        ConfigurationError(String msg, Exception x) {
-            super(msg);
-            this.exception = x;
-        } // <init>(String,Exception)
-
-        //
-        // Public methods
-        //
-
-        /** Returns the exception associated to this error. */
-        Exception getException() {
-            return exception;
-        } // getException():Exception
-
-    } // class ConfigurationError
-
-} // class ObjectFactory
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/cmdline/SecuritySupport.java	Thu Apr 12 08:38:26 2012 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,127 +0,0 @@
-/*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
- */
-/*
- * Copyright 2002-2004 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * 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: SecuritySupport.java,v 1.2.4.1 2005/08/31 11:30:44 pvedula Exp $
- */
-
-package com.sun.org.apache.xalan.internal.xsltc.cmdline;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.InputStream;
-
-import java.util.Properties;
-
-/**
- * This class is duplicated for each Xalan-Java subpackage so keep it in sync.
- * It is package private and therefore is not exposed as part of the Xalan-Java
- * API.
- *
- * Base class with security related methods that work on JDK 1.1.
- */
-class SecuritySupport {
-
-    /*
-     * Make this of type Object so that the verifier won't try to
-     * prove its type, thus possibly trying to load the SecuritySupport12
-     * class.
-     */
-    private static final Object securitySupport;
-
-    static {
-        SecuritySupport ss = null;
-        try {
-            Class c = Class.forName("java.security.AccessController");
-            // if that worked, we're on 1.2.
-            /*
-            // don't reference the class explicitly so it doesn't
-            // get dragged in accidentally.
-            c = Class.forName("javax.mail.SecuritySupport12");
-            Constructor cons = c.getConstructor(new Class[] { });
-            ss = (SecuritySupport)cons.newInstance(new Object[] { });
-            */
-            /*
-             * Unfortunately, we can't load the class using reflection
-             * because the class is package private.  And the class has
-             * to be package private so the APIs aren't exposed to other
-             * code that could use them to circumvent security.  Thus,
-             * we accept the risk that the direct reference might fail
-             * on some JDK 1.1 JVMs, even though we would never execute
-             * this code in such a case.  Sigh...
-             */
-            ss = new SecuritySupport12();
-        } catch (Exception ex) {
-            // ignore it
-        } finally {
-            if (ss == null)
-                ss = new SecuritySupport();
-            securitySupport = ss;
-        }
-    }
-
-    /**
-     * Return an appropriate instance of this class, depending on whether
-     * we're on a JDK 1.1 or J2SE 1.2 (or later) system.
-     */
-    static SecuritySupport getInstance() {
-        return (SecuritySupport)securitySupport;
-    }
-
-    ClassLoader getContextClassLoader() {
-        return null;
-    }
-
-    ClassLoader getSystemClassLoader() {
-        return null;
-    }
-
-    ClassLoader getParentClassLoader(ClassLoader cl) {
-        return null;
-    }
-
-    String getSystemProperty(String propName) {
-        return System.getProperty(propName);
-    }
-
-    FileInputStream getFileInputStream(File file)
-        throws FileNotFoundException
-    {
-        return new FileInputStream(file);
-    }
-
-    InputStream getResourceAsStream(ClassLoader cl, String name) {
-        InputStream ris;
-        if (cl == null) {
-            ris = ClassLoader.getSystemResourceAsStream(name);
-        } else {
-            ris = cl.getResourceAsStream(name);
-        }
-        return ris;
-    }
-
-    boolean getFileExists(File f) {
-        return f.exists();
-    }
-
-    long getLastModified(File f) {
-        return f.lastModified();
-    }
-}
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/cmdline/SecuritySupport12.java	Thu Apr 12 08:38:26 2012 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,148 +0,0 @@
-/*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
- */
-/*
- * Copyright 2002-2004 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * 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: SecuritySupport12.java,v 1.2.4.1 2005/08/31 11:33:55 pvedula Exp $
- */
-
-package com.sun.org.apache.xalan.internal.xsltc.cmdline;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.InputStream;
-
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
-
-import java.util.Properties;
-
-/**
- * This class is duplicated for each Xalan-Java subpackage so keep it in sync.
- * It is package private and therefore is not exposed as part of the Xalan-Java
- * API.
- *
- * Security related methods that only work on J2SE 1.2 and newer.
- */
-class SecuritySupport12 extends SecuritySupport {
-
-    ClassLoader getContextClassLoader() {
-        return (ClassLoader)
-                AccessController.doPrivileged(new PrivilegedAction() {
-            public Object run() {
-                ClassLoader cl = null;
-                try {
-                    cl = Thread.currentThread().getContextClassLoader();
-                } catch (SecurityException ex) { }
-                return cl;
-            }
-        });
-    }
-
-    ClassLoader getSystemClassLoader() {
-        return (ClassLoader)
-            AccessController.doPrivileged(new PrivilegedAction() {
-                public Object run() {
-                    ClassLoader cl = null;
-                    try {
-                        cl = ClassLoader.getSystemClassLoader();
-                    } catch (SecurityException ex) {}
-                    return cl;
-                }
-            });
-    }
-
-    ClassLoader getParentClassLoader(final ClassLoader cl) {
-        return (ClassLoader)
-            AccessController.doPrivileged(new PrivilegedAction() {
-                public Object run() {
-                    ClassLoader parent = null;
-                    try {
-                        parent = cl.getParent();
-                    } catch (SecurityException ex) {}
-
-                    // eliminate loops in case of the boot
-                    // ClassLoader returning itself as a parent
-                    return (parent == cl) ? null : parent;
-                }
-            });
-    }
-
-    String getSystemProperty(final String propName) {
-        return (String)
-            AccessController.doPrivileged(new PrivilegedAction() {
-                public Object run() {
-                    return System.getProperty(propName);
-                }
-            });
-    }
-
-    FileInputStream getFileInputStream(final File file)
-        throws FileNotFoundException
-    {
-        try {
-            return (FileInputStream)
-                AccessController.doPrivileged(new PrivilegedExceptionAction() {
-                    public Object run() throws FileNotFoundException {
-                        return new FileInputStream(file);
-                    }
-                });
-        } catch (PrivilegedActionException e) {
-            throw (FileNotFoundException)e.getException();
-        }
-    }
-
-    InputStream getResourceAsStream(final ClassLoader cl,
-                                           final String name)
-    {
-        return (InputStream)
-            AccessController.doPrivileged(new PrivilegedAction() {
-                public Object run() {
-                    InputStream ris;
-                    if (cl == null) {
-                        ris = ClassLoader.getSystemResourceAsStream(name);
-                    } else {
-                        ris = cl.getResourceAsStream(name);
-                    }
-                    return ris;
-                }
-            });
-    }
-
-    boolean getFileExists(final File f) {
-    return ((Boolean)
-            AccessController.doPrivileged(new PrivilegedAction() {
-                public Object run() {
-                    return new Boolean(f.exists());
-                }
-            })).booleanValue();
-    }
-
-    long getLastModified(final File f) {
-    return ((Long)
-            AccessController.doPrivileged(new PrivilegedAction() {
-                public Object run() {
-                    return new Long(f.lastModified());
-                }
-            })).longValue();
-    }
-
-}
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/cmdline/Transform.java	Thu Apr 12 08:38:26 2012 -0700
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/cmdline/Transform.java	Tue Apr 17 11:17:59 2012 -0700
@@ -49,6 +49,7 @@
 import com.sun.org.apache.xalan.internal.xsltc.StripFilter;
 import com.sun.org.apache.xml.internal.dtm.DTMWSFilter;
 import com.sun.org.apache.xalan.internal.xsltc.dom.DOMWSFilter;
+import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
 
 /**
  * @author Jacek Ambroziak
@@ -97,8 +98,7 @@
 
     private void doTransform() {
         try {
-            final Class clazz = ObjectFactory.findProviderClass(
-                _className, ObjectFactory.findClassLoader(), true);
+            final Class clazz = ObjectFactory.findProviderClass(_className, true);
             final AbstractTranslet translet = (AbstractTranslet)clazz.newInstance();
             translet.postInitialization();
 
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/AbsoluteLocationPath.java	Thu Apr 12 08:38:26 2012 -0700
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/AbsoluteLocationPath.java	Tue Apr 17 11:17:59 2012 -0700
@@ -106,13 +106,15 @@
             LocalVariableGen relPathIterator
                     = methodGen.addLocalVariable("abs_location_path_tmp",
                                        Util.getJCRefType(NODE_ITERATOR_SIG),
-                                       il.getEnd(), null);
-            il.append(new ASTORE(relPathIterator.getIndex()));
+                                       null, null);
+            relPathIterator.setStart(
+                    il.append(new ASTORE(relPathIterator.getIndex())));
 
             // Create new AbsoluteIterator
             il.append(new NEW(cpg.addClass(ABSOLUTE_ITERATOR)));
             il.append(DUP);
-            il.append(new ALOAD(relPathIterator.getIndex()));
+            relPathIterator.setEnd(
+                    il.append(new ALOAD(relPathIterator.getIndex())));
 
             // Initialize AbsoluteIterator with iterator from the stack
             il.append(new INVOKESPECIAL(initAI));
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/AbsolutePathPattern.java	Thu Apr 12 08:38:26 2012 -0700
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/AbsolutePathPattern.java	Tue Apr 17 11:17:59 2012 -0700
@@ -87,9 +87,9 @@
                     // absolute path pattern temporary
                     methodGen.addLocalVariable2("apptmp",
                                                 Util.getJCRefType(NODE_SIG),
-                                                il.getEnd());
+                                                null);
                 il.append(DUP);
-                il.append(new ISTORE(local.getIndex()));
+                local.setStart(il.append(new ISTORE(local.getIndex())));
                 _left.translate(classGen, methodGen);
                 il.append(methodGen.loadDOM());
                 local.setEnd(il.append(new ILOAD(local.getIndex())));
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/AttributeSet.java	Thu Apr 12 08:38:26 2012 -0700
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/AttributeSet.java	Tue Apr 17 11:17:59 2012 -0700
@@ -192,11 +192,7 @@
         final InstructionList il = methodGen.getInstructionList();
         il.append(RETURN);
 
-        methodGen.stripAttributes(true);
-        methodGen.setMaxLocals();
-        methodGen.setMaxStack();
-        methodGen.removeNOPs();
-        classGen.addMethod(methodGen.getMethod());
+        classGen.addMethod(methodGen);
     }
 
     public String toString() {
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Copy.java	Thu Apr 12 08:38:26 2012 -0700
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Copy.java	Tue Apr 17 11:17:59 2012 -0700
@@ -84,11 +84,11 @@
         final LocalVariableGen name =
             methodGen.addLocalVariable2("name",
                                         Util.getJCRefType(STRING_SIG),
-                                        il.getEnd());
+                                        null);
         final LocalVariableGen length =
             methodGen.addLocalVariable2("length",
                                         Util.getJCRefType("I"),
-                                        il.getEnd());
+                                        null);
 
         // Get the name of the node to copy and save for later
         il.append(methodGen.loadDOM());
@@ -102,7 +102,7 @@
                                                   + ")" + STRING_SIG);
         il.append(new INVOKEINTERFACE(cpy, 3));
         il.append(DUP);
-        il.append(new ASTORE(name.getIndex()));
+        name.setStart(il.append(new ASTORE(name.getIndex())));
         final BranchHandle ifBlock1 = il.append(new IFNULL(null));
 
         // Get the length of the node name and save for later
@@ -110,7 +110,7 @@
         final int lengthMethod = cpg.addMethodref(STRING_CLASS,"length","()I");
         il.append(new INVOKEVIRTUAL(lengthMethod));
         il.append(DUP);
-        il.append(new ISTORE(length.getIndex()));
+        length.setStart(il.append(new ISTORE(length.getIndex())));
 
         // Ignore attribute sets if current node is ROOT. DOM.shallowCopy()
         // returns "" for ROOT, so skip attribute sets if length == 0
@@ -144,10 +144,10 @@
 
         // Call the output handler's endElement() if we copied an element
         // (The DOM.shallowCopy() method calls startElement().)
-        il.append(new ILOAD(length.getIndex()));
+        length.setEnd(il.append(new ILOAD(length.getIndex())));
         final BranchHandle ifBlock3 = il.append(new IFEQ(null));
         il.append(methodGen.loadHandler());
-        il.append(new ALOAD(name.getIndex()));
+        name.setEnd(il.append(new ALOAD(name.getIndex())));
         il.append(methodGen.endElement());
 
         final InstructionHandle end = il.append(NOP);
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/FilterExpr.java	Thu Apr 12 08:38:26 2012 -0700
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/FilterExpr.java	Tue Apr 17 11:17:59 2012 -0700
@@ -28,11 +28,12 @@
 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.NEW;
+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.InstructionList;
+import com.sun.org.apache.bcel.internal.generic.ISTORE;
 import com.sun.org.apache.bcel.internal.generic.LocalVariableGen;
 import com.sun.org.apache.bcel.internal.generic.NEW;
 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
@@ -99,6 +100,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)  {
@@ -109,11 +111,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;
@@ -155,52 +160,95 @@
             translateFilterExpr(classGen, methodGen, predicateIndex);
         }
         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.
-
             // Get the next predicate to be translated
             Predicate predicate = (Predicate) _predicates.get(predicateIndex--);
 
             // Translate the rest of the predicates from right to left
             translatePredicates(classGen, methodGen, predicateIndex);
 
-            LocalVariableGen nodeIteratorTemp =
-                methodGen.addLocalVariable("filter_expr_tmp1",
-                                           Util.getJCRefType(NODE_ITERATOR_SIG),
-                                           il.getEnd(), null);
-            il.append(new ASTORE(nodeIteratorTemp.getIndex()));
+            if (predicate.isNthPositionFilter()) {
+                int nthIteratorIdx = cpg.addMethodref(NTH_ITERATOR_CLASS,
+                                       "<init>",
+                                       "("+NODE_ITERATOR_SIG+"I)V");
 
-            predicate.translate(classGen, methodGen);
-            LocalVariableGen filterTemp =
-                methodGen.addLocalVariable("filter_expr_tmp2",
-                              Util.getJCRefType(CURRENT_NODE_LIST_FILTER_SIG),
-                              il.getEnd(), null);
-            il.append(new ASTORE(filterTemp.getIndex()));
+                // 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
 
-            // Create a CurrentNodeListIterator
-            il.append(new NEW(cpg.addClass(CURRENT_NODE_LIST_ITERATOR)));
-            il.append(DUP);
+                // after we've created the suspect arguments to its constructor
 
-            // Initialize CurrentNodeListIterator
-            il.append(new ALOAD(nodeIteratorTemp.getIndex()));
-            il.append(ICONST_1);
-            il.append(new ALOAD(filterTemp.getIndex()));
-            il.append(methodGen.loadCurrentNode());
-            il.append(classGen.loadTranslet());
-            il.append(new INVOKESPECIAL(initCNLI));
+                // 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())));
+
+                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())));
+
+                // 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));
+            }
         }
     }
 }
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/FilterParentPath.java	Thu Apr 12 08:38:26 2012 -0700
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/FilterParentPath.java	Tue Apr 17 11:17:59 2012 -0700
@@ -128,20 +128,20 @@
         LocalVariableGen filterTemp =
                 methodGen.addLocalVariable("filter_parent_path_tmp1",
                                            Util.getJCRefType(NODE_ITERATOR_SIG),
-                                           il.getEnd(), null);
-        il.append(new ASTORE(filterTemp.getIndex()));
+                                           null, null);
+        filterTemp.setStart(il.append(new ASTORE(filterTemp.getIndex())));
 
         _path.translate(classGen, methodGen);
         LocalVariableGen pathTemp =
                 methodGen.addLocalVariable("filter_parent_path_tmp2",
                                            Util.getJCRefType(NODE_ITERATOR_SIG),
-                                           il.getEnd(), null);
-        il.append(new ASTORE(pathTemp.getIndex()));
+                                           null, null);
+        pathTemp.setStart(il.append(new ASTORE(pathTemp.getIndex())));
 
         il.append(new NEW(cpg.addClass(STEP_ITERATOR_CLASS)));
         il.append(DUP);
-        il.append(new ALOAD(filterTemp.getIndex()));
-        il.append(new ALOAD(pathTemp.getIndex()));
+        filterTemp.setEnd(il.append(new ALOAD(filterTemp.getIndex())));
+        pathTemp.setEnd(il.append(new ALOAD(pathTemp.getIndex())));
 
         // Initialize StepIterator with iterators from the stack
         il.append(new INVOKESPECIAL(initSI));
@@ -154,8 +154,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);
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/FilteredAbsoluteLocationPath.java	Thu Apr 12 08:38:26 2012 -0700
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/FilteredAbsoluteLocationPath.java	Tue Apr 17 11:17:59 2012 -0700
@@ -104,14 +104,14 @@
             LocalVariableGen pathTemp =
                methodGen.addLocalVariable("filtered_absolute_location_path_tmp",
                                           Util.getJCRefType(NODE_ITERATOR_SIG),
-                                          il.getEnd(), null);
+                                          null, null);
             _path.translate(classGen, methodGen);
-            il.append(new ASTORE(pathTemp.getIndex()));
+            pathTemp.setStart(il.append(new ASTORE(pathTemp.getIndex())));
 
             // Create new Dup Filter Iterator
             il.append(new NEW(cpg.addClass(DUP_FILTERED_ITERATOR)));
             il.append(DUP);
-            il.append(new ALOAD(pathTemp.getIndex()));
+            pathTemp.setEnd(il.append(new ALOAD(pathTemp.getIndex())));
 
             // Initialize Dup Filter Iterator with iterator from the stack
             il.append(new INVOKESPECIAL(initDFI));
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/FunctionAvailableCall.java	Thu Apr 12 08:38:26 2012 -0700
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/FunctionAvailableCall.java	Tue Apr 17 11:17:59 2012 -0700
@@ -35,6 +35,7 @@
 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Util;
+import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
 
 /**
  * @author G. Todd Miller
@@ -132,8 +133,7 @@
           methodName = replaceDash(methodName);
 
         try {
-            final Class clazz = ObjectFactory.findProviderClass(
-                className, ObjectFactory.findClassLoader(), true);
+            final Class clazz = ObjectFactory.findProviderClass(className, true);
 
             if (clazz == null) {
                 return false;
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/FunctionCall.java	Thu Apr 12 08:38:26 2012 -0700
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/FunctionCall.java	Tue Apr 17 11:17:59 2012 -0700
@@ -53,6 +53,7 @@
 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ReferenceType;
 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
+import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
 
 /**
  * @author Jacek Ambroziak
@@ -355,8 +356,7 @@
                 else {
                     if (_className != null && _className.length() > 0) {
                         try {
-                            _clazz = ObjectFactory.findProviderClass(
-                                _className, ObjectFactory.findClassLoader(), true);
+                            _clazz = ObjectFactory.findProviderClass(_className, true);
                             _namespace_format = NAMESPACE_FORMAT_CLASS;
                         }
                         catch (ClassNotFoundException e) {
@@ -775,8 +775,10 @@
                 paramTemp[i] =
                     methodGen.addLocalVariable("function_call_tmp"+i,
                                                expType.toJCType(),
-                                               il.getEnd(), null);
-                il.append(expType.STORE(paramTemp[i].getIndex()));
+                                               null, null);
+                paramTemp[i].setStart(
+                        il.append(expType.STORE(paramTemp[i].getIndex())));
+
             }
 
             il.append(new NEW(cpg.addClass(_className)));
@@ -784,7 +786,8 @@
 
             for (int i = 0; i < n; i++) {
                 final Expression arg = argument(i);
-                il.append(arg.getType().LOAD(paramTemp[i].getIndex()));
+                paramTemp[i].setEnd(
+                        il.append(arg.getType().LOAD(paramTemp[i].getIndex())));
             }
 
             final StringBuffer buffer = new StringBuffer();
@@ -882,8 +885,7 @@
             final int nArgs = _arguments.size();
             try {
               if (_clazz == null) {
-                _clazz = ObjectFactory.findProviderClass(
-                  _className, ObjectFactory.findClassLoader(), true);
+                _clazz = ObjectFactory.findProviderClass(_className, true);
 
                 if (_clazz == null) {
                   final ErrorMsg msg =
@@ -929,8 +931,7 @@
         final int nArgs = _arguments.size();
         try {
           if (_clazz == null) {
-            _clazz = ObjectFactory.findProviderClass(
-              _className, ObjectFactory.findClassLoader(), true);
+            _clazz = ObjectFactory.findProviderClass(_className, true);
 
             if (_clazz == null) {
               final ErrorMsg msg = new ErrorMsg(ErrorMsg.CLASS_NOT_FOUND_ERR, _className);
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Key.java	Thu Apr 12 08:38:26 2012 -0700
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Key.java	Tue Apr 17 11:17:59 2012 -0700
@@ -166,10 +166,10 @@
         final LocalVariableGen parentNode =
             methodGen.addLocalVariable("parentNode",
                                        Util.getJCRefType("I"),
-                                       il.getEnd(), null);
+                                       null, null);
 
         // Get the 'parameter' from the stack and store it in a local var.
-        il.append(new ISTORE(parentNode.getIndex()));
+        parentNode.setStart(il.append(new ISTORE(parentNode.getIndex())));
 
         // Save current node and current iterator on the stack
         il.append(methodGen.loadCurrentNode());
@@ -186,9 +186,9 @@
         // Prepare to call buildKeyIndex(String name, int node, String value);
         il.append(classGen.loadTranslet());
         il.append(new PUSH(cpg, _name.toString()));
-        il.append(new ILOAD(parentNode.getIndex()));
+        parentNode.setEnd(il.append(new ILOAD(parentNode.getIndex())));
 
-        // Now get the node value and feck it on the parameter stack
+        // Now get the node value and push it on the parameter stack
         il.append(methodGen.loadDOM());
         il.append(methodGen.loadCurrentNode());
         il.append(new INVOKEINTERFACE(getNodeValue, 2));
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Message.java	Thu Apr 12 08:38:26 2012 -0700
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Message.java	Tue Apr 17 11:17:59 2012 -0700
@@ -24,6 +24,7 @@
 package com.sun.org.apache.xalan.internal.xsltc.compiler;
 
 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.INVOKESPECIAL;
 import com.sun.org.apache.bcel.internal.generic.INVOKEVIRTUAL;
 import com.sun.org.apache.bcel.internal.generic.InstructionList;
@@ -97,36 +98,41 @@
                 // Invoke output.setWriter(STRING_WRITER)
                 il.append(methodGen.loadHandler());
                 il.append(SWAP);
-                il.append(new INVOKEVIRTUAL(
-                    cpg.addMethodref(OUTPUT_BASE, "setWriter",
-                                     "("+WRITER_SIG+")V")));
+                il.append(new INVOKEINTERFACE(
+                    cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE,
+                                              "setWriter",
+                                              "("+WRITER_SIG+")V"), 2));
 
                 // Invoke output.setEncoding("UTF-8")
                 il.append(methodGen.loadHandler());
                 il.append(new PUSH(cpg, "UTF-8"));   // other encodings?
-                il.append(new INVOKEVIRTUAL(
-                    cpg.addMethodref(OUTPUT_BASE, "setEncoding",
-                                     "("+STRING_SIG+")V")));
+                il.append(new INVOKEINTERFACE(
+                    cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE,
+                                              "setEncoding",
+                                              "("+STRING_SIG+")V"), 2));
 
                 // Invoke output.setOmitXMLDeclaration(true)
                 il.append(methodGen.loadHandler());
                 il.append(ICONST_1);
-                il.append(new INVOKEVIRTUAL(
-                    cpg.addMethodref(OUTPUT_BASE, "setOmitXMLDeclaration",
-                                     "(Z)V")));
+                il.append(new INVOKEINTERFACE(
+                    cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE,
+                                              "setOmitXMLDeclaration",
+                                              "(Z)V"), 2));
 
                 il.append(methodGen.loadHandler());
-                il.append(new INVOKEVIRTUAL(
-                    cpg.addMethodref(OUTPUT_BASE, "startDocument",
-                                     "()V")));
+                il.append(new INVOKEINTERFACE(
+                    cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE,
+                                              "startDocument",
+                                              "()V"), 1));
 
                 // Inline translation of contents
                 translateContents(classGen, methodGen);
 
                 il.append(methodGen.loadHandler());
-                il.append(new INVOKEVIRTUAL(
-                    cpg.addMethodref(OUTPUT_BASE, "endDocument",
-                                     "()V")));
+                il.append(new INVOKEINTERFACE(
+                    cpg.addInterfaceMethodref(TRANSLET_OUTPUT_INTERFACE,
+                                              "endDocument",
+                                              "()V"), 1));
 
                 // Call toString() on StringWriter
                 il.append(new INVOKEVIRTUAL(
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Mode.java	Thu Apr 12 08:38:26 2012 -0700
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Mode.java	Tue Apr 17 11:17:59 2012 -0700
@@ -553,11 +553,7 @@
         il.append(template.compile(classGen, methodGen));
         il.append(RETURN);
 
-        methodGen.stripAttributes(true);
-        methodGen.setMaxLocals();
-        methodGen.setMaxStack();
-        methodGen.removeNOPs();
-        classGen.addMethod(methodGen.getMethod());
+        classGen.addMethod(methodGen);
     }
 
     private void compileTemplates(ClassGenerator classGen,
@@ -765,12 +761,16 @@
                                 getClassName(), mainIL,
                                 classGen.getConstantPool());
         methodGen.addException("com.sun.org.apache.xalan.internal.xsltc.TransletException");
+        // Insert an extra NOP just to keep "current" from appearing as if it
+        // has a value before the start of the loop.
+        mainIL.append(NOP);
+
 
         // Create a local variable to hold the current node
         final LocalVariableGen current;
         current = methodGen.addLocalVariable2("current",
                                               com.sun.org.apache.bcel.internal.generic.Type.INT,
-                                              mainIL.getEnd());
+                                              null);
         _currentIndex = current.getIndex();
 
         // Create the "body" instruction list that will eventually hold the
@@ -793,6 +793,11 @@
         ifeq.setTarget(ilLoop.append(RETURN));  // applyTemplates() ends here!
         final InstructionHandle ihLoop = ilLoop.getStart();
 
+        current.setStart(mainIL.append(new GOTO_W(ihLoop)));
+
+        // Live range of "current" ends at end of loop
+        current.setEnd(loop);
+
         // Compile default handling of elements (traverse children)
         InstructionList ilRecurse =
             compileDefaultRecursion(classGen, methodGen, ihLoop);
@@ -1029,18 +1034,12 @@
         body.append(ilText);
 
         // putting together constituent instruction lists
-        mainIL.append(new GOTO_W(ihLoop));
         mainIL.append(body);
         // fall through to ilLoop
         mainIL.append(ilLoop);
 
         peepHoleOptimization(methodGen);
-        methodGen.stripAttributes(true);
-
-        methodGen.setMaxLocals();
-        methodGen.setMaxStack();
-        methodGen.removeNOPs();
-        classGen.addMethod(methodGen.getMethod());
+        classGen.addMethod(methodGen);
 
         // Compile method(s) for <xsl:apply-imports/> for this mode
         if (_importLevels != null) {
@@ -1131,11 +1130,11 @@
         final LocalVariableGen current;
         current = methodGen.addLocalVariable2("current",
                                               com.sun.org.apache.bcel.internal.generic.Type.INT,
-                                              mainIL.getEnd());
+                                              null);
         _currentIndex = current.getIndex();
 
-    mainIL.append(new ILOAD(methodGen.getLocalIndex(NODE_PNAME)));
-    mainIL.append(new ISTORE(_currentIndex));
+        mainIL.append(new ILOAD(methodGen.getLocalIndex(NODE_PNAME)));
+        current.setStart(mainIL.append(new ISTORE(_currentIndex)));
 
         // Create the "body" instruction list that will eventually hold the
         // code for the entire method (other ILs will be appended).
@@ -1145,7 +1144,7 @@
         // Create an instruction list that contains the default next-node
         // iteration
         final InstructionList ilLoop = new InstructionList();
-    ilLoop.append(RETURN);
+        ilLoop.append(RETURN);
         final InstructionHandle ihLoop = ilLoop.getStart();
 
         // Compile default handling of elements (traverse children)
@@ -1385,16 +1384,15 @@
 
         // putting together constituent instruction lists
         mainIL.append(body);
+
+        // Mark the end of the live range for the "current" variable
+        current.setEnd(body.getEnd());
+
         // fall through to ilLoop
         mainIL.append(ilLoop);
 
         peepHoleOptimization(methodGen);
-        methodGen.stripAttributes(true);
-
-        methodGen.setMaxLocals();
-        methodGen.setMaxStack();
-        methodGen.removeNOPs();
-        classGen.addMethod(methodGen.getMethod());
+        classGen.addMethod(methodGen);
 
         // Restore original (complete) set of templates for this transformation
         _templates = oldTemplates;
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Number.java	Thu Apr 12 08:38:26 2012 -0700
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Number.java	Tue Apr 17 11:17:59 2012 -0700
@@ -323,10 +323,7 @@
         il.append(new INVOKESPECIAL(index));
         il.append(RETURN);
 
-        cons.stripAttributes(true);
-        cons.setMaxLocals();
-        cons.setMaxStack();
-        classGen.addMethod(cons.getMethod());
+        classGen.addMethod(cons);
     }
 
     /**
@@ -349,7 +346,7 @@
                                 ITERATOR_FIELD_SIG);
         il.append(ALOAD_0); // 'this' pointer on stack
         il.append(new GETFIELD(field));
-        il.append(new ASTORE(local.getIndex()));
+        local.setStart(il.append(new ASTORE(local.getIndex())));
         matchGen.setIteratorIndex(local.getIndex());
 
         // Get NodeCounter._translet and store locally
@@ -361,7 +358,7 @@
         il.append(ALOAD_0); // 'this' pointer on stack
         il.append(new GETFIELD(field));
         il.append(new CHECKCAST(cpg.addClass(TRANSLET_CLASS)));
-        il.append(new ASTORE(local.getIndex()));
+        local.setStart(il.append(new ASTORE(local.getIndex())));
         nodeCounterGen.setTransletIndex(local.getIndex());
 
         // Get NodeCounter._document and store locally
@@ -372,7 +369,7 @@
         il.append(ALOAD_0); // 'this' pointer on stack
         il.append(new GETFIELD(field));
         // Make sure we have the correct DOM type on the stack!!!
-        il.append(new ASTORE(local.getIndex()));
+        local.setStart(il.append(new ASTORE(local.getIndex())));
         matchGen.setDomIndex(local.getIndex());
     }
 
@@ -436,11 +433,7 @@
             _from.synthesize(nodeCounterGen, matchGen);
             il.append(IRETURN);
 
-            matchGen.stripAttributes(true);
-            matchGen.setMaxLocals();
-            matchGen.setMaxStack();
-            matchGen.removeNOPs();
-            nodeCounterGen.addMethod(matchGen.getMethod());
+            nodeCounterGen.addMethod(matchGen);
         }
 
         /*
@@ -467,11 +460,7 @@
 
             il.append(IRETURN);
 
-            matchGen.stripAttributes(true);
-            matchGen.setMaxLocals();
-            matchGen.setMaxStack();
-            matchGen.removeNOPs();
-            nodeCounterGen.addMethod(matchGen.getMethod());
+            nodeCounterGen.addMethod(matchGen);
         }
 
         getXSLTC().dumpClass(nodeCounterGen.getJavaClass());
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/ObjectFactory.java	Thu Apr 12 08:38:26 2012 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,663 +0,0 @@
-/*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
- */
-/*
- * Copyright 2001-2004 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * 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: ObjectFactory.java,v 1.2.4.1 2005/09/12 10:51:22 pvedula Exp $
- */
-
-package com.sun.org.apache.xalan.internal.xsltc.compiler;
-
-import java.io.InputStream;
-import java.io.IOException;
-import java.io.File;
-import java.io.FileInputStream;
-
-import java.util.Properties;
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
-
-/**
- * This class is duplicated for each JAXP subpackage so keep it in sync.
- * It is package private and therefore is not exposed as part of the JAXP
- * API.
- * <p>
- * This code is designed to implement the JAXP 1.1 spec pluggability
- * feature and is designed to run on JDK version 1.1 and
- * later, and to compile on JDK 1.2 and onward.
- * The code also runs both as part of an unbundled jar file and
- * when bundled as part of the JDK.
- * <p>
- * This class was moved from the <code>javax.xml.parsers.ObjectFactory</code>
- * class and modified to be used as a general utility for creating objects
- * dynamically.
- *
- * @version $Id: ObjectFactory.java,v 1.9 2008/04/02 00:41:01 joehw Exp $
- */
-class ObjectFactory {
-
-    //
-    // Constants
-    //
-
-    // name of default properties file to look for in JDK's jre/lib directory
-    private static final String DEFAULT_PROPERTIES_FILENAME =
-                                                     "xalan.properties";
-
-    private static final String SERVICES_PATH = "META-INF/services/";
-
-    /** Set to true for debugging */
-    private static final boolean DEBUG = false;
-
-    /** cache the contents of the xalan.properties file.
-     *  Until an attempt has been made to read this file, this will
-     * be null; if the file does not exist or we encounter some other error
-     * during the read, this will be empty.
-     */
-    private static Properties fXalanProperties = null;
-
-    /***
-     * Cache the time stamp of the xalan.properties file so
-     * that we know if it's been modified and can invalidate
-     * the cache when necessary.
-     */
-    private static long fLastModified = -1;
-
-    //
-    // Public static methods
-    //
-
-    /**
-     * Finds the implementation Class object in the specified order.  The
-     * specified order is the following:
-     * <ol>
-     *  <li>query the system property using <code>System.getProperty</code>
-     *  <li>read <code>META-INF/services/<i>factoryId</i></code> file
-     *  <li>use fallback classname
-     * </ol>
-     *
-     * @return instance of factory, never null
-     *
-     * @param factoryId             Name of the factory to find, same as
-     *                              a property name
-     * @param fallbackClassName     Implementation class name, if nothing else
-     *                              is found.  Use null to mean no fallback.
-     *
-     * @exception ObjectFactory.ConfigurationError
-     */
-    static Object createObject(String factoryId, String fallbackClassName)
-        throws ConfigurationError {
-        return createObject(factoryId, null, fallbackClassName);
-    } // createObject(String,String):Object
-
-    /**
-     * Finds the implementation Class object in the specified order.  The
-     * specified order is the following:
-     * <ol>
-     *  <li>query the system property using <code>System.getProperty</code>
-     *  <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
-     *  <li>read <code>META-INF/services/<i>factoryId</i></code> file
-     *  <li>use fallback classname
-     * </ol>
-     *
-     * @return instance of factory, never null
-     *
-     * @param factoryId             Name of the factory to find, same as
-     *                              a property name
-     * @param propertiesFilename The filename in the $java.home/lib directory
-     *                           of the properties file.  If none specified,
-     *                           ${java.home}/lib/xalan.properties will be used.
-     * @param fallbackClassName     Implementation class name, if nothing else
-     *                              is found.  Use null to mean no fallback.
-     *
-     * @exception ObjectFactory.ConfigurationError
-     */
-    static Object createObject(String factoryId,
-                                      String propertiesFilename,
-                                      String fallbackClassName)
-        throws ConfigurationError
-    {
-        Class factoryClass = lookUpFactoryClass(factoryId,
-                                                propertiesFilename,
-                                                fallbackClassName);
-
-        if (factoryClass == null) {
-            throw new ConfigurationError(
-                "Provider for " + factoryId + " cannot be found", null);
-        }
-
-        try{
-            Object instance = factoryClass.newInstance();
-            if (DEBUG) debugPrintln("created new instance of factory " + factoryId);
-            return instance;
-        } catch (Exception x) {
-            throw new ConfigurationError(
-                "Provider for factory " + factoryId
-                    + " could not be instantiated: " + x, x);
-        }
-    } // createObject(String,String,String):Object
-
-    /**
-     * Finds the implementation Class object in the specified order.  The
-     * specified order is the following:
-     * <ol>
-     *  <li>query the system property using <code>System.getProperty</code>
-     *  <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
-     *  <li>read <code>META-INF/services/<i>factoryId</i></code> file
-     *  <li>use fallback classname
-     * </ol>
-     *
-     * @return Class object of factory, never null
-     *
-     * @param factoryId             Name of the factory to find, same as
-     *                              a property name
-     * @param propertiesFilename The filename in the $java.home/lib directory
-     *                           of the properties file.  If none specified,
-     *                           ${java.home}/lib/xalan.properties will be used.
-     * @param fallbackClassName     Implementation class name, if nothing else
-     *                              is found.  Use null to mean no fallback.
-     *
-     * @exception ObjectFactory.ConfigurationError
-     */
-    static Class lookUpFactoryClass(String factoryId)
-        throws ConfigurationError
-    {
-        return lookUpFactoryClass(factoryId, null, null);
-    } // lookUpFactoryClass(String):Class
-
-    /**
-     * Finds the implementation Class object in the specified order.  The
-     * specified order is the following:
-     * <ol>
-     *  <li>query the system property using <code>System.getProperty</code>
-     *  <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
-     *  <li>read <code>META-INF/services/<i>factoryId</i></code> file
-     *  <li>use fallback classname
-     * </ol>
-     *
-     * @return Class object that provides factory service, never null
-     *
-     * @param factoryId             Name of the factory to find, same as
-     *                              a property name
-     * @param propertiesFilename The filename in the $java.home/lib directory
-     *                           of the properties file.  If none specified,
-     *                           ${java.home}/lib/xalan.properties will be used.
-     * @param fallbackClassName     Implementation class name, if nothing else
-     *                              is found.  Use null to mean no fallback.
-     *
-     * @exception ObjectFactory.ConfigurationError
-     */
-    static Class lookUpFactoryClass(String factoryId,
-                                           String propertiesFilename,
-                                           String fallbackClassName)
-        throws ConfigurationError
-    {
-        String factoryClassName = lookUpFactoryClassName(factoryId,
-                                                         propertiesFilename,
-                                                         fallbackClassName);
-        ClassLoader cl = findClassLoader();
-
-        if (factoryClassName == null) {
-            factoryClassName = fallbackClassName;
-        }
-
-        // assert(className != null);
-        try{
-            Class providerClass = findProviderClass(factoryClassName,
-                                                    cl,
-                                                    true);
-            if (DEBUG) debugPrintln("created new instance of " + providerClass +
-                   " using ClassLoader: " + cl);
-            return providerClass;
-        } catch (ClassNotFoundException x) {
-            throw new ConfigurationError(
-                "Provider " + factoryClassName + " not found", x);
-        } catch (Exception x) {
-            throw new ConfigurationError(
-                "Provider "+factoryClassName+" could not be instantiated: "+x,
-                x);
-        }
-    } // lookUpFactoryClass(String,String,String):Class
-
-    /**
-     * Finds the name of the required implementation class in the specified
-     * order.  The specified order is the following:
-     * <ol>
-     *  <li>query the system property using <code>System.getProperty</code>
-     *  <li>read <code>$java.home/lib/<i>propertiesFilename</i></code> file
-     *  <li>read <code>META-INF/services/<i>factoryId</i></code> file
-     *  <li>use fallback classname
-     * </ol>
-     *
-     * @return name of class that provides factory service, never null
-     *
-     * @param factoryId             Name of the factory to find, same as
-     *                              a property name
-     * @param propertiesFilename The filename in the $java.home/lib directory
-     *                           of the properties file.  If none specified,
-     *                           ${java.home}/lib/xalan.properties will be used.
-     * @param fallbackClassName     Implementation class name, if nothing else
-     *                              is found.  Use null to mean no fallback.
-     *
-     * @exception ObjectFactory.ConfigurationError
-     */
-    static String lookUpFactoryClassName(String factoryId,
-                                                String propertiesFilename,
-                                                String fallbackClassName)
-    {
-        SecuritySupport ss = SecuritySupport.getInstance();
-
-        // Use the system property first
-        try {
-            String systemProp = ss.getSystemProperty(factoryId);
-            if (systemProp != null) {
-                if (DEBUG) debugPrintln("found system property, value=" + systemProp);
-                return systemProp;
-            }
-        } catch (SecurityException se) {
-            // Ignore and continue w/ next location
-        }
-
-        // Try to read from propertiesFilename, or
-        // $java.home/lib/xalan.properties
-        String factoryClassName = null;
-        // no properties file name specified; use
-        // $JAVA_HOME/lib/xalan.properties:
-        if (propertiesFilename == null) {
-            File propertiesFile = null;
-            boolean propertiesFileExists = false;
-            try {
-                String javah = ss.getSystemProperty("java.home");
-                propertiesFilename = javah + File.separator +
-                    "lib" + File.separator + DEFAULT_PROPERTIES_FILENAME;
-                propertiesFile = new File(propertiesFilename);
-                propertiesFileExists = ss.getFileExists(propertiesFile);
-            } catch (SecurityException e) {
-                // try again...
-                fLastModified = -1;
-                fXalanProperties = null;
-            }
-
-            synchronized (ObjectFactory.class) {
-                boolean loadProperties = false;
-                FileInputStream fis = null;
-                try {
-                    // file existed last time
-                    if(fLastModified >= 0) {
-                        if(propertiesFileExists &&
-                                (fLastModified < (fLastModified = ss.getLastModified(propertiesFile)))) {
-                            loadProperties = true;
-                        } else {
-                            // file has stopped existing...
-                            if(!propertiesFileExists) {
-                                fLastModified = -1;
-                                fXalanProperties = null;
-                            } // else, file wasn't modified!
-                        }
-                    } else {
-                        // file has started to exist:
-                        if(propertiesFileExists) {
-                            loadProperties = true;
-                            fLastModified = ss.getLastModified(propertiesFile);
-                        } // else, nothing's changed
-                    }
-                    if(loadProperties) {
-                        // must never have attempted to read xalan.properties
-                        // before (or it's outdeated)
-                        fXalanProperties = new Properties();
-                        fis = ss.getFileInputStream(propertiesFile);
-                        fXalanProperties.load(fis);
-                    }
-                } catch (Exception x) {
-                    fXalanProperties = null;
-                    fLastModified = -1;
-                    // assert(x instanceof FileNotFoundException
-                    //        || x instanceof SecurityException)
-                    // In both cases, ignore and continue w/ next location
-                }
-                finally {
-                    // try to close the input stream if one was opened.
-                    if (fis != null) {
-                        try {
-                            fis.close();
-                        }
-                        // Ignore the exception.
-                        catch (IOException exc) {}
-                    }
-                }
-            }
-            if(fXalanProperties != null) {
-                factoryClassName = fXalanProperties.getProperty(factoryId);
-            }
-        } else {
-            FileInputStream fis = null;
-            try {
-                fis = ss.getFileInputStream(new File(propertiesFilename));
-                Properties props = new Properties();
-                props.load(fis);
-                factoryClassName = props.getProperty(factoryId);
-            } catch (Exception x) {
-                // assert(x instanceof FileNotFoundException
-                //        || x instanceof SecurityException)
-                // In both cases, ignore and continue w/ next location
-            }
-            finally {
-                // try to close the input stream if one was opened.
-                if (fis != null) {
-                    try {
-                        fis.close();
-                    }
-                    // Ignore the exception.
-                    catch (IOException exc) {}
-                }
-            }
-        }
-        if (factoryClassName != null) {
-            if (DEBUG) debugPrintln("found in " + propertiesFilename + ", value="
-                          + factoryClassName);
-            return factoryClassName;
-        }
-
-        // Try Jar Service Provider Mechanism
-        return findJarServiceProviderName(factoryId);
-    } // lookUpFactoryClass(String,String):String
-
-    //
-    // Private static methods
-    //
-
-    /** Prints a message to standard error if debugging is enabled. */
-    private static void debugPrintln(String msg) {
-        if (DEBUG) {
-            System.err.println("JAXP: " + msg);
-        }
-    } // debugPrintln(String)
-
-    /**
-     * Figure out which ClassLoader to use.  For JDK 1.2 and later use
-     * the context ClassLoader.
-     */
-    static ClassLoader findClassLoader()
-        throws ConfigurationError
-    {
-        SecuritySupport ss = SecuritySupport.getInstance();
-
-        // Figure out which ClassLoader to use for loading the provider
-        // class.  If there is a Context ClassLoader then use it.
-        ClassLoader context = ss.getContextClassLoader();
-        ClassLoader system = ss.getSystemClassLoader();
-
-        ClassLoader chain = system;
-        while (true) {
-            if (context == chain) {
-                // Assert: we are on JDK 1.1 or we have no Context ClassLoader
-                // or any Context ClassLoader in chain of system classloader
-                // (including extension ClassLoader) so extend to widest
-                // ClassLoader (always look in system ClassLoader if Xalan
-                // is in boot/extension/system classpath and in current
-                // ClassLoader otherwise); normal classloaders delegate
-                // back to system ClassLoader first so this widening doesn't
-                // change the fact that context ClassLoader will be consulted
-                ClassLoader current = ObjectFactory.class.getClassLoader();
-
-                chain = system;
-                while (true) {
-                    if (current == chain) {
-                        // Assert: Current ClassLoader in chain of
-                        // boot/extension/system ClassLoaders
-                        return system;
-                    }
-                    if (chain == null) {
-                        break;
-                    }
-                    chain = ss.getParentClassLoader(chain);
-                }
-
-                // Assert: Current ClassLoader not in chain of
-                // boot/extension/system ClassLoaders
-                return current;
-            }
-
-            if (chain == null) {
-                // boot ClassLoader reached
-                break;
-            }
-
-            // Check for any extension ClassLoaders in chain up to
-            // boot ClassLoader
-            chain = ss.getParentClassLoader(chain);
-        };
-
-        // Assert: Context ClassLoader not in chain of
-        // boot/extension/system ClassLoaders
-        return context;
-    } // findClassLoader():ClassLoader
-
-    /**
-     * Create an instance of a class using the specified ClassLoader
-     */
-    static Object newInstance(String className, ClassLoader cl,
-                                      boolean doFallback)
-        throws ConfigurationError
-    {
-        // assert(className != null);
-        try{
-            Class providerClass = findProviderClass(className, cl, doFallback);
-            Object instance = providerClass.newInstance();
-            if (DEBUG) debugPrintln("created new instance of " + providerClass +
-                   " using ClassLoader: " + cl);
-            return instance;
-        } catch (ClassNotFoundException x) {
-            throw new ConfigurationError(
-                "Provider " + className + " not found", x);
-        } catch (Exception x) {
-            throw new ConfigurationError(
-                "Provider " + className + " could not be instantiated: " + x,
-                x);
-        }
-    }
-
-    /**
-     * Find a Class using the specified ClassLoader
-     */
-    static Class findProviderClass(String className, ClassLoader cl,
-                                           boolean doFallback)
-        throws ClassNotFoundException, ConfigurationError
-    {
-        //throw security exception if the calling thread is not allowed to access the
-        //class. Restrict the access to the package classes as specified in java.security policy.
-        SecurityManager security = System.getSecurityManager();
-        try{
-                if (security != null){
-                    final int lastDot = className.lastIndexOf(".");
-                    String packageName = className;
-                    if (lastDot != -1) packageName = className.substring(0, lastDot);
-                    security.checkPackageAccess(packageName);
-                 }
-        }catch(SecurityException e){
-            throw e;
-        }
-
-        Class providerClass;
-        if (cl == null) {
-            // XXX Use the bootstrap ClassLoader.  There is no way to
-            // load a class using the bootstrap ClassLoader that works
-            // in both JDK 1.1 and Java 2.  However, this should still
-            // work b/c the following should be true:
-            //
-            // (cl == null) iff current ClassLoader == null
-            //
-            // Thus Class.forName(String) will use the current
-            // ClassLoader which will be the bootstrap ClassLoader.
-            providerClass = Class.forName(className);
-        } else {
-            try {
-                providerClass = cl.loadClass(className);
-            } catch (ClassNotFoundException x) {
-                if (doFallback) {
-                    // Fall back to current classloader
-                    ClassLoader current = ObjectFactory.class.getClassLoader();
-                    if (current == null) {
-                        providerClass = Class.forName(className);
-                    } else if (cl != current) {
-                        cl = current;
-                        providerClass = cl.loadClass(className);
-                    } else {
-                        throw x;
-                    }
-                } else {
-                    throw x;
-                }
-            }
-        }
-
-        return providerClass;
-    }
-
-    /**
-     * Find the name of service provider using Jar Service Provider Mechanism
-     *
-     * @return instance of provider class if found or null
-     */
-    private static String findJarServiceProviderName(String factoryId)
-    {
-        SecuritySupport ss = SecuritySupport.getInstance();
-        String serviceId = SERVICES_PATH + factoryId;
-        InputStream is = null;
-
-        // First try the Context ClassLoader
-        ClassLoader cl = findClassLoader();
-
-        is = ss.getResourceAsStream(cl, serviceId);
-
-        // If no provider found then try the current ClassLoader
-        if (is == null) {
-            ClassLoader current = ObjectFactory.class.getClassLoader();
-            if (cl != current) {
-                cl = current;
-                is = ss.getResourceAsStream(cl, serviceId);
-            }
-        }
-
-        if (is == null) {
-            // No provider found
-            return null;
-        }
-
-        if (DEBUG) debugPrintln("found jar resource=" + serviceId +
-               " using ClassLoader: " + cl);
-
-        // Read the service provider name in UTF-8 as specified in
-        // the jar spec.  Unfortunately this fails in Microsoft
-        // VJ++, which does not implement the UTF-8
-        // encoding. Theoretically, we should simply let it fail in
-        // that case, since the JVM is obviously broken if it
-        // doesn't support such a basic standard.  But since there
-        // are still some users attempting to use VJ++ for
-        // development, we have dropped in a fallback which makes a
-        // second attempt using the platform's default encoding. In
-        // VJ++ this is apparently ASCII, which is a subset of
-        // UTF-8... and since the strings we'll be reading here are
-        // also primarily limited to the 7-bit ASCII range (at
-        // least, in English versions), this should work well
-        // enough to keep us on the air until we're ready to
-        // officially decommit from VJ++. [Edited comment from
-        // jkesselm]
-        BufferedReader rd;
-        try {
-            rd = new BufferedReader(new InputStreamReader(is, "UTF-8"));
-        } catch (java.io.UnsupportedEncodingException e) {
-            rd = new BufferedReader(new InputStreamReader(is));
-        }
-
-        String factoryClassName = null;
-        try {
-            // XXX Does not handle all possible input as specified by the
-            // Jar Service Provider specification
-            factoryClassName = rd.readLine();
-        } catch (IOException x) {
-            // No provider found
-            return null;
-        }
-        finally {
-            try {
-                // try to close the reader.
-                rd.close();
-            }
-            // Ignore the exception.
-            catch (IOException exc) {}
-        }
-
-        if (factoryClassName != null &&
-            ! "".equals(factoryClassName)) {
-            if (DEBUG) debugPrintln("found in resource, value="
-                   + factoryClassName);
-
-            // Note: here we do not want to fall back to the current
-            // ClassLoader because we want to avoid the case where the
-            // resource file was found using one ClassLoader and the
-            // provider class was instantiated using a different one.
-            return factoryClassName;
-        }
-
-        // No provider found
-        return null;
-    }
-
-    //
-    // Classes
-    //
-
-    /**
-     * A configuration error.
-     */
-    static class ConfigurationError
-        extends Error {
-                static final long serialVersionUID = 3326843611085065902L;
-        //
-        // Data
-        //
-
-        /** Exception. */
-        private Exception exception;
-
-        //
-        // Constructors
-        //
-
-        /**
-         * Construct a new instance with the specified detail string and
-         * exception.
-         */
-        ConfigurationError(String msg, Exception x) {
-            super(msg);
-            this.exception = x;
-        } // <init>(String,Exception)
-
-        //
-        // Public methods
-        //
-
-        /** Returns the exception associated to this error. */
-        Exception getException() {
-            return exception;
-        } // getException():Exception
-
-    } // class ConfigurationError
-
-} // class ObjectFactory
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/ParameterRef.java	Thu Apr 12 08:38:26 2012 -0700
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/ParameterRef.java	Tue Apr 17 11:17:59 2012 -0700
@@ -84,12 +84,10 @@
                 }
                 else {
                     il.append(_variable.loadInstruction());
-                    _variable.removeReference(this);
                 }
             }
             else {
                 il.append(_variable.loadInstruction());
-                _variable.removeReference(this);
             }
         }
         else {
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/ParentLocationPath.java	Thu Apr 12 08:38:26 2012 -0700
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/ParentLocationPath.java	Tue Apr 17 11:17:59 2012 -0700
@@ -190,15 +190,15 @@
         LocalVariableGen pathTemp
                 = methodGen.addLocalVariable("parent_location_path_tmp1",
                                          Util.getJCRefType(NODE_ITERATOR_SIG),
-                                         il.getEnd(), null);
-        il.append(new ASTORE(pathTemp.getIndex()));
+                                         null, null);
+        pathTemp.setStart(il.append(new ASTORE(pathTemp.getIndex())));
 
         _step.translate(classGen, methodGen);
         LocalVariableGen stepTemp
                 = methodGen.addLocalVariable("parent_location_path_tmp2",
                                          Util.getJCRefType(NODE_ITERATOR_SIG),
-                                         il.getEnd(), null);
-        il.append(new ASTORE(stepTemp.getIndex()));
+                                         null, null);
+        stepTemp.setStart(il.append(new ASTORE(stepTemp.getIndex())));
 
         // Create new StepIterator
         final int initSI = cpg.addMethodref(STEP_ITERATOR_CLASS,
@@ -210,8 +210,8 @@
         il.append(new NEW(cpg.addClass(STEP_ITERATOR_CLASS)));
         il.append(DUP);
 
-        il.append(new ALOAD(pathTemp.getIndex()));
-        il.append(new ALOAD(stepTemp.getIndex()));
+        pathTemp.setEnd(il.append(new ALOAD(pathTemp.getIndex())));
+        stepTemp.setEnd(il.append(new ALOAD(stepTemp.getIndex())));
 
         // Initialize StepIterator with iterators from the stack
         il.append(new INVOKESPECIAL(initSI));
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/ParentPattern.java	Thu Apr 12 08:38:26 2012 -0700
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/ParentPattern.java	Tue Apr 17 11:17:59 2012 -0700
@@ -27,6 +27,7 @@
 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.ISTORE;
+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;
 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
@@ -77,7 +78,7 @@
         final LocalVariableGen local =
             methodGen.addLocalVariable2("ppt",
                                         Util.getJCRefType(NODE_SIG),
-                                        il.getEnd());
+                                        null);
 
         final com.sun.org.apache.bcel.internal.generic.Instruction loadLocal =
             new ILOAD(local.getIndex());
@@ -90,7 +91,7 @@
         }
         else if (_right instanceof StepPattern) {
             il.append(DUP);
-            il.append(storeLocal);
+            local.setStart(il.append(storeLocal));
 
             _right.translate(classGen, methodGen);
 
@@ -119,7 +120,11 @@
         }
         else {
             il.append(DUP);
-            il.append(storeLocal);
+            InstructionHandle storeInst = il.append(storeLocal);
+
+            if (local.getStart() == null) {
+                local.setStart(storeInst);
+            }
 
             _left.translate(classGen, methodGen);
 
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Parser.java	Thu Apr 12 08:38:26 2012 -0700
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Parser.java	Tue Apr 17 11:17:59 2012 -0700
@@ -44,6 +44,8 @@
 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodType;
 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;
+import com.sun.org.apache.xalan.internal.utils.FactoryImpl;
+import com.sun.org.apache.xalan.internal.utils.ObjectFactory;
 import org.xml.sax.Attributes;
 import org.xml.sax.helpers.AttributesImpl;
 import org.xml.sax.ContentHandler;
@@ -93,8 +95,11 @@
 
     private int _currentImportPrecedence;
 
-    public Parser(XSLTC xsltc) {
+    private boolean _useServicesMechanism = true;
+
+    public Parser(XSLTC xsltc, boolean useServicesMechanism) {
         _xsltc = xsltc;
+        _useServicesMechanism = useServicesMechanism;
     }
 
     public void init() {
@@ -306,17 +311,22 @@
         }
         else {
             Dictionary space = (Dictionary)_namespaces.get(namespace);
+            String lexicalQName =
+                       (prefix == null || prefix.length() == 0)
+                            ? localname
+                            : (prefix + ':' + localname);
+
             if (space == null) {
                 final QName name = new QName(namespace, prefix, localname);
                 _namespaces.put(namespace, space = new Hashtable());
-                space.put(localname, name);
+                space.put(lexicalQName, name);
                 return name;
             }
             else {
-                QName name = (QName)space.get(localname);
+                QName name = (QName)space.get(lexicalQName);
                 if (name == null) {
                     name = new QName(namespace, prefix, localname);
-                    space.put(localname, name);
+                    space.put(lexicalQName, name);
                 }
                 return name;
             }
@@ -449,7 +459,7 @@
     public SyntaxTreeNode parse(InputSource input) {
         try {
             // Create a SAX parser and get the XMLReader object it uses
-            final SAXParserFactory factory = SAXParserFactory.newInstance();
+            final SAXParserFactory factory = FactoryImpl.getSAXFactory(_useServicesMechanism);
 
             if (_xsltc.isSecureProcessing()) {
                 try {
@@ -918,8 +928,7 @@
 
         if (className != null) {
             try {
-                final Class clazz = ObjectFactory.findProviderClass(
-                    className, ObjectFactory.findClassLoader(), true);
+                final Class clazz = ObjectFactory.findProviderClass(className, true);
                 node = (SyntaxTreeNode)clazz.newInstance();
                 node.setQName(qname);
                 node.setParser(this);
@@ -1273,7 +1282,7 @@
             // handled at this point in order to correctly generate
             // Fallback elements from <xsl:fallback>s.
             getSymbolTable().setCurrentNode(element);
-            ((Stylesheet)element).excludeExtensionPrefixes(this);
+            ((Stylesheet)element).declareExtensionPrefixes(this);
         }
 
         _prefixMapping = null;
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Predicate.java	Thu Apr 12 08:38:26 2012 -0700
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Predicate.java	Tue Apr 17 11:17:59 2012 -0700
@@ -412,7 +412,7 @@
         il.append(new CHECKCAST(cpg.addClass(className)));
         il.append(new GETFIELD(cpg.addFieldref(className,
                                                DOM_FIELD, DOM_INTF_SIG)));
-        il.append(new ASTORE(local.getIndex()));
+        local.setStart(il.append(new ASTORE(local.getIndex())));
 
         // Store the dom index in the test generator
         testGen.setDomIndex(local.getIndex());
@@ -420,12 +420,8 @@
         _exp.translate(filterGen, testGen);
         il.append(IRETURN);
 
-        testGen.stripAttributes(true);
-        testGen.setMaxLocals();
-        testGen.setMaxStack();
-        testGen.removeNOPs();
         filterGen.addEmptyConstructor(ACC_PUBLIC);
-        filterGen.addMethod(testGen.getMethod());
+        filterGen.addMethod(testGen);
 
         getXSLTC().dumpClass(filterGen.getJavaClass());
     }
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/ProcessingInstruction.java	Thu Apr 12 08:38:26 2012 -0700
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/ProcessingInstruction.java	Tue Apr 17 11:17:59 2012 -0700
@@ -83,13 +83,14 @@
 
         if (!_isLiteral) {
             // if the ncname is an AVT, then the ncname has to be checked at runtime if it is a valid ncname
-            LocalVariableGen nameValue = methodGen.addLocalVariable2("nameValue",
+            LocalVariableGen nameValue =
+                    methodGen.addLocalVariable2("nameValue",
             Util.getJCRefType(STRING_SIG),
-            il.getEnd());
+                                                null);
 
             // store the name into a variable first so _name.translate only needs to be called once
             _name.translate(classGen, methodGen);
-            il.append(new ASTORE(nameValue.getIndex()));
+            nameValue.setStart(il.append(new ASTORE(nameValue.getIndex())));
             il.append(new ALOAD(nameValue.getIndex()));
 
             // call checkNCName if the name is an AVT
@@ -104,7 +105,7 @@
             il.append(DUP);     // first arg to "attributes" call
 
             // load name value again
-            il.append(new ALOAD(nameValue.getIndex()));
+            nameValue.setEnd(il.append(new ALOAD(nameValue.getIndex())));
         } else {
             // Save the current handler base on the stack
             il.append(methodGen.loadHandler());
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/SecuritySupport.java	Thu Apr 12 08:38:26 2012 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,127 +0,0 @@
-/*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
- */
-/*
- * Copyright 2002-2004 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * 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: SecuritySupport.java,v 1.2.4.1 2005/09/05 08:57:13 pvedula Exp $
- */
-
-package com.sun.org.apache.xalan.internal.xsltc.compiler;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.InputStream;
-
-import java.util.Properties;
-
-/**
- * This class is duplicated for each Xalan-Java subpackage so keep it in sync.
- * It is package private and therefore is not exposed as part of the Xalan-Java
- * API.
- *
- * Base class with security related methods that work on JDK 1.1.
- */
-class SecuritySupport {
-
-    /*
-     * Make this of type Object so that the verifier won't try to
-     * prove its type, thus possibly trying to load the SecuritySupport12
-     * class.
-     */
-    private static final Object securitySupport;
-
-    static {
-        SecuritySupport ss = null;
-        try {
-            Class c = Class.forName("java.security.AccessController");
-            // if that worked, we're on 1.2.
-            /*
-            // don't reference the class explicitly so it doesn't
-            // get dragged in accidentally.
-            c = Class.forName("javax.mail.SecuritySupport12");
-            Constructor cons = c.getConstructor(new Class[] { });
-            ss = (SecuritySupport)cons.newInstance(new Object[] { });
-            */
-            /*
-             * Unfortunately, we can't load the class using reflection
-             * because the class is package private.  And the class has
-             * to be package private so the APIs aren't exposed to other
-             * code that could use them to circumvent security.  Thus,
-             * we accept the risk that the direct reference might fail
-             * on some JDK 1.1 JVMs, even though we would never execute
-             * this code in such a case.  Sigh...
-             */
-            ss = new SecuritySupport12();
-        } catch (Exception ex) {
-            // ignore it
-        } finally {
-            if (ss == null)
-                ss = new SecuritySupport();
-            securitySupport = ss;
-        }
-    }
-
-    /**
-     * Return an appropriate instance of this class, depending on whether
-     * we're on a JDK 1.1 or J2SE 1.2 (or later) system.
-     */
-    static SecuritySupport getInstance() {
-        return (SecuritySupport)securitySupport;
-    }
-
-    ClassLoader getContextClassLoader() {
-        return null;
-    }
-
-    ClassLoader getSystemClassLoader() {
-        return null;
-    }
-
-    ClassLoader getParentClassLoader(ClassLoader cl) {
-        return null;
-    }
-
-    String getSystemProperty(String propName) {
-        return System.getProperty(propName);
-    }
-
-    FileInputStream getFileInputStream(File file)
-        throws FileNotFoundException
-    {
-        return new FileInputStream(file);
-    }
-
-    InputStream getResourceAsStream(ClassLoader cl, String name) {
-        InputStream ris;
-        if (cl == null) {
-            ris = ClassLoader.getSystemResourceAsStream(name);
-        } else {
-            ris = cl.getResourceAsStream(name);
-        }
-        return ris;
-    }
-
-    boolean getFileExists(File f) {
-        return f.exists();
-    }
-
-    long getLastModified(File f) {
-        return f.lastModified();
-    }
-}
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/SecuritySupport12.java	Thu Apr 12 08:38:26 2012 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,148 +0,0 @@
-/*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
- */
-/*
- * Copyright 2002-2004 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.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * 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: SecuritySupport12.java,v 1.2.4.1 2005/09/05 08:58:02 pvedula Exp $
- */
-
-package com.sun.org.apache.xalan.internal.xsltc.compiler;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.InputStream;
-
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
-
-import java.util.Properties;
-
-/**
- * This class is duplicated for each Xalan-Java subpackage so keep it in sync.
- * It is package private and therefore is not exposed as part of the Xalan-Java
- * API.
- *
- * Security related methods that only work on J2SE 1.2 and newer.
- */
-class SecuritySupport12 extends SecuritySupport {
-
-    ClassLoader getContextClassLoader() {
-        return (ClassLoader)
-                AccessController.doPrivileged(new PrivilegedAction() {
-            public Object run() {
-                ClassLoader cl = null;
-                try {
-                    cl = Thread.currentThread().getContextClassLoader();
-                } catch (SecurityException ex) { }
-                return cl;
-            }
-        });
-    }
-
-    ClassLoader getSystemClassLoader() {
-        return (ClassLoader)
-            AccessController.doPrivileged(new PrivilegedAction() {
-                public Object run() {
-                    ClassLoader cl = null;
-                    try {
-                        cl = ClassLoader.getSystemClassLoader();
-                    } catch (SecurityException ex) {}
-                    return cl;
-                }
-            });
-    }
-
-    ClassLoader getParentClassLoader(final ClassLoader cl) {
-        return (ClassLoader)
-            AccessController.doPrivileged(new PrivilegedAction() {
-                public Object run() {
-                    ClassLoader parent = null;
-                    try {
-                        parent = cl.getParent();
-                    } catch (SecurityException ex) {}
-
-                    // eliminate loops in case of the boot
-                    // ClassLoader returning itself as a parent
-                    return (parent == cl) ? null : parent;
-                }
-            });
-    }
-
-    String getSystemProperty(final String propName) {
-        return (String)
-            AccessController.doPrivileged(new PrivilegedAction() {
-                public Object run() {
-                    return System.getProperty(propName);
-                }
-            });
-    }
-
-    FileInputStream getFileInputStream(final File file)
-        throws FileNotFoundException
-    {
-        try {
-            return (FileInputStream)
-                AccessController.doPrivileged(new PrivilegedExceptionAction() {
-                    public Object run() throws FileNotFoundException {
-                        return new FileInputStream(file);
-                    }
-                });
-        } catch (PrivilegedActionException e) {
-            throw (FileNotFoundException)e.getException();
-        }
-    }
-
-    InputStream getResourceAsStream(final ClassLoader cl,
-                                           final String name)
-    {
-        return (InputStream)
-            AccessController.doPrivileged(new PrivilegedAction() {
-                public Object run() {
-                    InputStream ris;
-                    if (cl == null) {
-                        ris = ClassLoader.getSystemResourceAsStream(name);
-                    } else {
-                        ris = cl.getResourceAsStream(name);
-                    }
-                    return ris;
-                }
-            });
-    }
-
-    boolean getFileExists(final File f) {
-    return ((Boolean)
-            AccessController.doPrivileged(new PrivilegedAction() {
-                public Object run() {
-                    return new Boolean(f.exists());
-                }
-            })).booleanValue();
-    }
-
-    long getLastModified(final File f) {
-    return ((Long)
-            AccessController.doPrivileged(new PrivilegedAction() {
-                public Object run() {
-                    return new Long(f.lastModified());
-                }
-            })).longValue();
-    }
-
-}
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Sort.java	Thu Apr 12 08:38:26 2012 -0700
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Sort.java	Tue Apr 17 11:17:59 2012 -0700
@@ -270,12 +270,12 @@
         LocalVariableGen nodesTemp =
             methodGen.addLocalVariable("sort_tmp1",
                                        Util.getJCRefType(NODE_ITERATOR_SIG),
-                                       il.getEnd(), null);
+                                       null, null);
 
         LocalVariableGen sortRecordFactoryTemp =
             methodGen.addLocalVariable("sort_tmp2",
                                       Util.getJCRefType(NODE_SORT_FACTORY_SIG),
-                                      il.getEnd(), null);
+                                      null, null);
 
         // Get the current node iterator
         if (nodeSet == null) {  // apply-templates default
@@ -291,17 +291,19 @@
             nodeSet.translate(classGen, methodGen);
         }
 
-        il.append(new ASTORE(nodesTemp.getIndex()));
+        nodesTemp.setStart(il.append(new ASTORE(nodesTemp.getIndex())));
 
         // Compile the code for the NodeSortRecord producing class and pass
         // that as the last argument to the SortingIterator constructor.
         compileSortRecordFactory(sortObjects, classGen, methodGen);
-        il.append(new ASTORE(sortRecordFactoryTemp.getIndex()));
+        sortRecordFactoryTemp.setStart(
+                il.append(new ASTORE(sortRecordFactoryTemp.getIndex())));
 
         il.append(new NEW(cpg.addClass(SORT_ITERATOR)));
         il.append(DUP);
-        il.append(new ALOAD(nodesTemp.getIndex()));
-        il.append(new ALOAD(sortRecordFactoryTemp.getIndex()));
+        nodesTemp.setEnd(il.append(new ALOAD(nodesTemp.getIndex())));
+        sortRecordFactoryTemp.setEnd(
+                il.append(new ALOAD(sortRecordFactoryTemp.getIndex())));
         il.append(new INVOKESPECIAL(init));
     }
 
@@ -346,7 +348,7 @@
         LocalVariableGen sortOrderTemp
                  = methodGen.addLocalVariable("sort_order_tmp",
                                       Util.getJCRefType("[" + STRING_SIG),
-                                      il.getEnd(), null);
+                                      null, null);
         il.append(new PUSH(cpg, nsorts));
         il.append(new ANEWARRAY(cpg.addClass(STRING)));
         for (int level = 0; level < nsorts; level++) {
@@ -356,12 +358,12 @@
             sort.translateSortOrder(classGen, methodGen);
             il.append(AASTORE);
         }
-        il.append(new ASTORE(sortOrderTemp.getIndex()));
+        sortOrderTemp.setStart(il.append(new ASTORE(sortOrderTemp.getIndex())));
 
         LocalVariableGen sortTypeTemp
                  = methodGen.addLocalVariable("sort_type_tmp",
                                       Util.getJCRefType("[" + STRING_SIG),
-                                      il.getEnd(), null);
+                                      null, null);
         il.append(new PUSH(cpg, nsorts));
         il.append(new ANEWARRAY(cpg.addClass(STRING)));
         for (int level = 0; level < nsorts; level++) {
@@ -371,12 +373,12 @@
             sort.translateSortType(classGen, methodGen);
             il.append(AASTORE);
         }
-        il.append(new ASTORE(sortTypeTemp.getIndex()));
+        sortTypeTemp.setStart(il.append(new ASTORE(sortTypeTemp.getIndex())));
 
         LocalVariableGen sortLangTemp
                  = methodGen.addLocalVariable("sort_lang_tmp",
                                       Util.getJCRefType("[" + STRING_SIG),
-                                      il.getEnd(), null);
+                                      null, null);
         il.append(new PUSH(cpg, nsorts));
         il.append(new ANEWARRAY(cpg.addClass(STRING)));
         for (int level = 0; level < nsorts; level++) {
@@ -386,12 +388,12 @@
               sort.translateLang(classGen, methodGen);
               il.append(AASTORE);
         }
-        il.append(new ASTORE(sortLangTemp.getIndex()));
+        sortLangTemp.setStart(il.append(new ASTORE(sortLangTemp.getIndex())));
 
         LocalVariableGen sortCaseOrderTemp
                  = methodGen.addLocalVariable("sort_case_order_tmp",
                                       Util.getJCRefType("[" + STRING_SIG),
-                                      il.getEnd(), null);
+                                      null, null);
         il.append(new PUSH(cpg, nsorts));
         il.append(new ANEWARRAY(cpg.addClass(STRING)));
         for (int level = 0; level < nsorts; level++) {
@@ -401,7 +403,8 @@
             sort.translateCaseOrder(classGen, methodGen);
             il.append(AASTORE);
         }
-        il.append(new ASTORE(sortCaseOrderTemp.getIndex()));
+        sortCaseOrderTemp.setStart(
+                il.append(new ASTORE(sortCaseOrderTemp.getIndex())));
 
         il.append(new NEW(cpg.addClass(sortRecordFactoryClass)));
         il.append(DUP);
@@ -409,10 +412,11 @@
         il.append(new PUSH(cpg, sortRecordClass));
         il.append(classGen.loadTranslet());
 
-        il.append(new ALOAD(sortOrderTemp.getIndex()));
-        il.append(new ALOAD(sortTypeTemp.getIndex()));
-        il.append(new ALOAD(sortLangTemp.getIndex()));
-        il.append(new ALOAD(sortCaseOrderTemp.getIndex()));
+        sortOrderTemp.setEnd(il.append(new ALOAD(sortOrderTemp.getIndex())));
+        sortTypeTemp.setEnd(il.append(new ALOAD(sortTypeTemp.getIndex())));
+        sortLangTemp.setEnd(il.append(new ALOAD(sortLangTemp.getIndex())));
+        sortCaseOrderTemp.setEnd(
+                il.append(new ALOAD(sortCaseOrderTemp.getIndex())));
 
         il.append(new INVOKESPECIAL(
             cpg.addMethodref(sortRecordFactoryClass, "<init>",
@@ -584,10 +588,10 @@
 
         constructor.setMaxLocals();
         constructor.setMaxStack();
-        sortRecordFactory.addMethod(constructor.getMethod());
+        sortRecordFactory.addMethod(constructor);
         makeNodeSortRecord.setMaxLocals();
         makeNodeSortRecord.setMaxStack();
-        sortRecordFactory.addMethod(makeNodeSortRecord.getMethod());
+        sortRecordFactory.addMethod(makeNodeSortRecord);
         xsltc.dumpClass(sortRecordFactory.getJavaClass());
 
         return className;
@@ -640,9 +644,9 @@
             }
         }
 
-        Method init = compileInit(sortObjects, sortRecord,
+        MethodGenerator init = compileInit(sortObjects, sortRecord,
                                          cpg, className);
-        Method extract = compileExtract(sortObjects, sortRecord,
+        MethodGenerator extract = compileExtract(sortObjects, sortRecord,
                                         cpg, className);
         sortRecord.addMethod(init);
         sortRecord.addMethod(extract);
@@ -656,7 +660,7 @@
      * collator in the super calls only when the stylesheet specifies a new
      * language in xsl:sort.
      */
-    private static Method compileInit(Vector sortObjects,
+    private static MethodGenerator compileInit(Vector sortObjects,
                                            NodeSortRecordGenerator sortRecord,
                                            ConstantPoolGen cpg,
                                            String className)
@@ -677,18 +681,14 @@
 
         il.append(RETURN);
 
-        init.stripAttributes(true);
-        init.setMaxLocals();
-        init.setMaxStack();
-
-        return init.getMethod();
+        return init;
     }
 
 
     /**
      * Compiles a method that overloads NodeSortRecord.extractValueFromDOM()
      */
-    private static Method compileExtract(Vector sortObjects,
+    private static MethodGenerator compileExtract(Vector sortObjects,
                                          NodeSortRecordGenerator sortRecord,
                                          ConstantPoolGen cpg,
                                          String className) {
@@ -745,11 +745,6 @@
             il.append(ARETURN);
         }
 
-        extractMethod.stripAttributes(true);
-        extractMethod.setMaxLocals();
-        extractMethod.setMaxStack();
-        extractMethod.removeNOPs();
-
-        return extractMethod.getMethod();
+        return extractMethod;
     }
 }
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Step.java	Thu Apr 12 08:38:26 2012 -0700
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Step.java	Tue Apr 17 11:17:59 2012 -0700
@@ -447,20 +447,24 @@
                 LocalVariableGen iteratorTemp
                         = methodGen.addLocalVariable("step_tmp1",
                                          Util.getJCRefType(NODE_ITERATOR_SIG),
-                                         il.getEnd(), null);
-                il.append(new ASTORE(iteratorTemp.getIndex()));
+                                         null, null);
+                iteratorTemp.setStart(
+                        il.append(new ASTORE(iteratorTemp.getIndex())));
 
                 predicate.translate(classGen, methodGen);
                 LocalVariableGen predicateValueTemp
                         = methodGen.addLocalVariable("step_tmp2",
                                          Util.getJCRefType("I"),
-                                         il.getEnd(), null);
-                il.append(new ISTORE(predicateValueTemp.getIndex()));
+                                         null, null);
+                predicateValueTemp.setStart(
+                        il.append(new ISTORE(predicateValueTemp.getIndex())));
 
                 il.append(new NEW(cpg.addClass(NTH_ITERATOR_CLASS)));
                 il.append(DUP);
-                il.append(new ALOAD(iteratorTemp.getIndex()));
-                il.append(new ILOAD(predicateValueTemp.getIndex()));
+                iteratorTemp.setEnd(
+                        il.append(new ALOAD(iteratorTemp.getIndex())));
+                predicateValueTemp.setEnd(
+                        il.append(new ILOAD(predicateValueTemp.getIndex())));
                 il.append(new INVOKESPECIAL(idx));
             }
             else {
@@ -486,22 +490,24 @@
                 LocalVariableGen iteratorTemp
                         = methodGen.addLocalVariable("step_tmp1",
                                          Util.getJCRefType(NODE_ITERATOR_SIG),
-                                         il.getEnd(), null);
-                il.append(new ASTORE(iteratorTemp.getIndex()));
+                                         null, null);
+                iteratorTemp.setStart(
+                        il.append(new ASTORE(iteratorTemp.getIndex())));
 
                 predicate.translateFilter(classGen, methodGen);
                 LocalVariableGen filterTemp
                         = methodGen.addLocalVariable("step_tmp2",
                               Util.getJCRefType(CURRENT_NODE_LIST_FILTER_SIG),
-                              il.getEnd(), null);
-                il.append(new ASTORE(filterTemp.getIndex()));
-
+                              null, null);
+                filterTemp.setStart(
+                        il.append(new ASTORE(filterTemp.getIndex())));
                 // create new CurrentNodeListIterator
                 il.append(new NEW(cpg.addClass(CURRENT_NODE_LIST_ITERATOR)));
                 il.append(DUP);
 
-                il.append(new ALOAD(iteratorTemp.getIndex()));
-                il.append(new ALOAD(filterTemp.getIndex()));
+                iteratorTemp.setEnd(
+                        il.append(new ALOAD(iteratorTemp.getIndex())));
+                filterTemp.setEnd(il.append(new ALOAD(filterTemp.getIndex())));
 
                 il.append(methodGen.loadCurrentNode());
                 il.append(classGen.loadTranslet());
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/StepPattern.java	Thu Apr 12 08:38:26 2012 -0700
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/StepPattern.java	Tue Apr 17 11:17:59 2012 -0700
@@ -328,8 +328,8 @@
         LocalVariableGen match;
         match = methodGen.addLocalVariable("step_pattern_tmp1",
                                            Util.getJCRefType(NODE_SIG),
-                                           il.getEnd(), null);
-        il.append(new ISTORE(match.getIndex()));
+                                           null, null);
+        match.setStart(il.append(new ISTORE(match.getIndex())));
 
         // If pattern not reduced then check kernel
         if (!_isEpsilon) {
@@ -358,13 +358,15 @@
         LocalVariableGen stepIteratorTemp =
                 methodGen.addLocalVariable("step_pattern_tmp2",
                                            Util.getJCRefType(NODE_ITERATOR_SIG),
-                                           il.getEnd(), null);
-        il.append(new ASTORE(stepIteratorTemp.getIndex()));
+                                           null, null);
+        stepIteratorTemp.setStart(
+                il.append(new ASTORE(stepIteratorTemp.getIndex())));
 
         il.append(new NEW(cpg.addClass(MATCHING_ITERATOR)));
         il.append(DUP);
         il.append(new ILOAD(match.getIndex()));
-        il.append(new ALOAD(stepIteratorTemp.getIndex()));
+        stepIteratorTemp.setEnd(
+                il.append(new ALOAD(stepIteratorTemp.getIndex())));
         il.append(new INVOKESPECIAL(index));
 
         // Get the parent of the matching node
@@ -378,7 +380,7 @@
 
         // Overwrite current iterator and current node
         il.append(methodGen.storeIterator());
-        il.append(new ILOAD(match.getIndex()));
+        match.setEnd(il.append(new ILOAD(match.getIndex())));
         il.append(methodGen.storeCurrentNode());
 
         // Translate the expression of the predicate
@@ -415,13 +417,13 @@
         // Store node on the stack into a local variable
         node = methodGen.addLocalVariable("step_pattern_tmp1",
                                           Util.getJCRefType(NODE_SIG),
-                                          il.getEnd(), null);
-        il.append(new ISTORE(node.getIndex()));
+                                          null, null);
+        node.setStart(il.append(new ISTORE(node.getIndex())));
 
         // Create a new local to store the iterator
         iter = methodGen.addLocalVariable("step_pattern_tmp2",
                                           Util.getJCRefType(NODE_ITERATOR_SIG),
-                                          il.getEnd(), null);
+                                          null, null);
 
         // Add a new private field if this is the main class
         if (!classGen.isExternal()) {
@@ -438,20 +440,24 @@
             il.append(classGen.loadTranslet());
             il.append(new GETFIELD(iteratorIndex));
             il.append(DUP);
-            il.append(new ASTORE(iter.getIndex()));
+            iter.setStart(il.append(new ASTORE(iter.getIndex())));
             ifBlock = il.append(new IFNONNULL(null));
             il.append(classGen.loadTranslet());
         }
 
         // Compile the step created at type checking time
         _step.translate(classGen, methodGen);
-        il.append(new ASTORE(iter.getIndex()));
+        InstructionHandle iterStore = il.append(new ASTORE(iter.getIndex()));
 
         // If in the main class update the field too
         if (!classGen.isExternal()) {
             il.append(new ALOAD(iter.getIndex()));
             il.append(new PUTFIELD(iteratorIndex));
             ifBlock.setTarget(il.append(NOP));
+        } else {
+            // If class is not external, start of range for iter variable was
+            // set above
+            iter.setStart(iterStore);
         }
 
         // Get the parent of the node on the stack
@@ -478,10 +484,11 @@
         InstructionHandle begin, next;
         node2 = methodGen.addLocalVariable("step_pattern_tmp3",
                                            Util.getJCRefType(NODE_SIG),
-                                           il.getEnd(), null);
+                                           null, null);
 
         skipNext = il.append(new GOTO(null));
         next = il.append(new ALOAD(iter.getIndex()));
+        node2.setStart(next);
         begin = il.append(methodGen.nextNode());
         il.append(DUP);
         il.append(new ISTORE(node2.getIndex()));
@@ -489,10 +496,10 @@
 
         il.append(new ILOAD(node2.getIndex()));
         il.append(new ILOAD(node.getIndex()));
-        il.append(new IF_ICMPLT(next));
+        iter.setEnd(il.append(new IF_ICMPLT(next)));
 
-        il.append(new ILOAD(node2.getIndex()));
-        il.append(new ILOAD(node.getIndex()));
+        node2.setEnd(il.append(new ILOAD(node2.getIndex())));
+        node.setEnd(il.append(new ILOAD(node.getIndex())));
         _falseList.add(il.append(new IF_ICMPNE(null)));
 
         skipNext.setTarget(begin);
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Stylesheet.java	Thu Apr 12 08:38:26 2012 -0700
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Stylesheet.java	Tue Apr 17 11:17:59 2012 -0700
@@ -23,9 +23,6 @@
 
 package com.sun.org.apache.xalan.internal.xsltc.compiler;
 
-import java.net.URL;
-import java.net.MalformedURLException;
-
 import java.util.Vector;
 import java.util.Enumeration;
 import java.util.Hashtable;
@@ -203,8 +200,9 @@
 
     /**
      * Set to true to enable template inlining optimization.
+     * @see XSLTC#_templateInlining
      */
-    private boolean _templateInlining = true;
+    private boolean _templateInlining = false;
 
     /**
      * A reference to the last xsl:output object found in the styleshet.
@@ -467,11 +465,11 @@
             for (int i = 0; i < n; i++) {
                 final Template template = (Template)templates.elementAt(i);
                 if (template.hasParams()) {
-                    _hasLocalParams = new Boolean(true);
+                    _hasLocalParams = Boolean.TRUE;
                     return true;
                 }
             }
-            _hasLocalParams = new Boolean(false);
+            _hasLocalParams = Boolean.FALSE;
             return false;
         }
         else {
@@ -509,15 +507,9 @@
         return (_extensions.get(uri) != null);
     }
 
-    public void excludeExtensionPrefixes(Parser parser) {
+    public void declareExtensionPrefixes(Parser parser) {
         final SymbolTable stable = parser.getSymbolTable();
-        final String excludePrefixes = getAttribute("exclude-result-prefixes");
         final String extensionPrefixes = getAttribute("extension-element-prefixes");
-
-        // Exclude XSLT uri
-        stable.excludeURI(Constants.XSLT_URI);
-        stable.excludeNamespaces(excludePrefixes);
-        stable.excludeNamespaces(extensionPrefixes);
         extensionURI(extensionPrefixes, stable);
     }
 
@@ -571,6 +563,16 @@
      * Parse all direct children of the <xsl:stylesheet/> element.
      */
     public final void parseOwnChildren(Parser parser) {
+        final SymbolTable stable = parser.getSymbolTable();
+        final String excludePrefixes = getAttribute("exclude-result-prefixes");
+        final String extensionPrefixes = getAttribute("extension-element-prefixes");
+
+        // Exclude XSLT uri
+        stable.pushExcludedNamespacesContext();
+        stable.excludeURI(Constants.XSLT_URI);
+        stable.excludeNamespaces(excludePrefixes);
+        stable.excludeNamespaces(extensionPrefixes);
+
         final Vector contents = getContents();
         final int count = contents.size();
 
@@ -602,6 +604,8 @@
                 template.setName(parser.getQName(name));
             }
         }
+
+        stable.popExcludedNamespacesContext();
     }
 
     public void processModes() {
@@ -801,81 +805,99 @@
             }
         }
 
+        staticConst.markChunkStart();
         il.append(new PUSH(cpg, size));
         il.append(new ANEWARRAY(cpg.addClass(STRING)));
+        int namesArrayRef = cpg.addFieldref(_className,
+                                            STATIC_NAMES_ARRAY_FIELD,
+                                            NAMES_INDEX_SIG);
+        il.append(new PUTSTATIC(namesArrayRef));
+        staticConst.markChunkEnd();
 
         for (int i = 0; i < size; i++) {
             final String name = namesArray[i];
-            il.append(DUP);
+            staticConst.markChunkStart();
+            il.append(new GETSTATIC(namesArrayRef));
             il.append(new PUSH(cpg, i));
             il.append(new PUSH(cpg, name));
             il.append(AASTORE);
+            staticConst.markChunkEnd();
         }
-        il.append(new PUTSTATIC(cpg.addFieldref(_className,
-                                               STATIC_NAMES_ARRAY_FIELD,
-                                               NAMES_INDEX_SIG)));
 
+        staticConst.markChunkStart();
         il.append(new PUSH(cpg, size));
         il.append(new ANEWARRAY(cpg.addClass(STRING)));
+        int urisArrayRef = cpg.addFieldref(_className,
+                                           STATIC_URIS_ARRAY_FIELD,
+                                           URIS_INDEX_SIG);
+        il.append(new PUTSTATIC(urisArrayRef));
+        staticConst.markChunkEnd();
 
         for (int i = 0; i < size; i++) {
             final String uri = urisArray[i];
-            il.append(DUP);
+            staticConst.markChunkStart();
+            il.append(new GETSTATIC(urisArrayRef));
             il.append(new PUSH(cpg, i));
             il.append(new PUSH(cpg, uri));
             il.append(AASTORE);
+            staticConst.markChunkEnd();
         }
-        il.append(new PUTSTATIC(cpg.addFieldref(_className,
-                                               STATIC_URIS_ARRAY_FIELD,
-                                               URIS_INDEX_SIG)));
 
+        staticConst.markChunkStart();
         il.append(new PUSH(cpg, size));
         il.append(new NEWARRAY(BasicType.INT));
+        int typesArrayRef = cpg.addFieldref(_className,
+                                            STATIC_TYPES_ARRAY_FIELD,
+                                            TYPES_INDEX_SIG);
+        il.append(new PUTSTATIC(typesArrayRef));
+        staticConst.markChunkEnd();
 
         for (int i = 0; i < size; i++) {
             final int nodeType = typesArray[i];
-            il.append(DUP);
+            staticConst.markChunkStart();
+            il.append(new GETSTATIC(typesArrayRef));
             il.append(new PUSH(cpg, i));
             il.append(new PUSH(cpg, nodeType));
             il.append(IASTORE);
         }
-        il.append(new PUTSTATIC(cpg.addFieldref(_className,
-                                               STATIC_TYPES_ARRAY_FIELD,
-                                               TYPES_INDEX_SIG)));
 
         // Put the namespace names array into the translet
         final Vector namespaces = getXSLTC().getNamespaceIndex();
+        staticConst.markChunkStart();
         il.append(new PUSH(cpg, namespaces.size()));
         il.append(new ANEWARRAY(cpg.addClass(STRING)));
+        int namespaceArrayRef = cpg.addFieldref(_className,
+                                                STATIC_NAMESPACE_ARRAY_FIELD,
+                                                NAMESPACE_INDEX_SIG);
+        il.append(new PUTSTATIC(namespaceArrayRef));
+        staticConst.markChunkEnd();
 
         for (int i = 0; i < namespaces.size(); i++) {
             final String ns = (String)namespaces.elementAt(i);
-            il.append(DUP);
+            staticConst.markChunkStart();
+            il.append(new GETSTATIC(namespaceArrayRef));
             il.append(new PUSH(cpg, i));
             il.append(new PUSH(cpg, ns));
             il.append(AASTORE);
+            staticConst.markChunkEnd();
         }
-        il.append(new PUTSTATIC(cpg.addFieldref(_className,
-                                               STATIC_NAMESPACE_ARRAY_FIELD,
-                                               NAMESPACE_INDEX_SIG)));
 
         // Grab all the literal text in the stylesheet and put it in a char[]
         final int charDataCount = getXSLTC().getCharacterDataCount();
         final int toCharArray = cpg.addMethodref(STRING, "toCharArray", "()[C");
         for (int i = 0; i < charDataCount; i++) {
+            staticConst.markChunkStart();
             il.append(new PUSH(cpg, getXSLTC().getCharacterData(i)));
             il.append(new INVOKEVIRTUAL(toCharArray));
             il.append(new PUTSTATIC(cpg.addFieldref(_className,
                                                STATIC_CHAR_DATA_FIELD+i,
                                                STATIC_CHAR_DATA_FIELD_SIG)));
+            staticConst.markChunkEnd();
         }
 
         il.append(RETURN);
 
-        staticConst.stripAttributes(true);
-        staticConst.setMaxLocals();
-        staticConst.setMaxStack();
-        classGen.addMethod(staticConst.getMethod());
+        classGen.addMethod(staticConst);
 
     }
 
@@ -898,6 +920,7 @@
         il.append(new INVOKESPECIAL(cpg.addMethodref(TRANSLET_CLASS,
                                                      "<init>", "()V")));
 
+        constructor.markChunkStart();
         il.append(classGen.loadTranslet());
         il.append(new GETSTATIC(cpg.addFieldref(_className,
                                                 STATIC_NAMES_ARRAY_FIELD,
@@ -913,7 +936,9 @@
         il.append(new PUTFIELD(cpg.addFieldref(TRANSLET_CLASS,
                                                URIS_INDEX,
                                                URIS_INDEX_SIG)));
+        constructor.markChunkEnd();
 
+        constructor.markChunkStart();
         il.append(classGen.loadTranslet());
         il.append(new GETSTATIC(cpg.addFieldref(_className,
                                                 STATIC_TYPES_ARRAY_FIELD,
@@ -921,7 +946,9 @@
         il.append(new PUTFIELD(cpg.addFieldref(TRANSLET_CLASS,
                                                TYPES_INDEX,
                                                TYPES_INDEX_SIG)));
+        constructor.markChunkEnd();
 
+        constructor.markChunkStart();
         il.append(classGen.loadTranslet());
         il.append(new GETSTATIC(cpg.addFieldref(_className,
                                                 STATIC_NAMESPACE_ARRAY_FIELD,
@@ -929,38 +956,45 @@
         il.append(new PUTFIELD(cpg.addFieldref(TRANSLET_CLASS,
                                                NAMESPACE_INDEX,
                                                NAMESPACE_INDEX_SIG)));
+        constructor.markChunkEnd();
 
+        constructor.markChunkStart();
         il.append(classGen.loadTranslet());
         il.append(new PUSH(cpg, AbstractTranslet.CURRENT_TRANSLET_VERSION));
         il.append(new PUTFIELD(cpg.addFieldref(TRANSLET_CLASS,
                                                TRANSLET_VERSION_INDEX,
                                                TRANSLET_VERSION_INDEX_SIG)));
+        constructor.markChunkEnd();
 
         if (_hasIdCall) {
+            constructor.markChunkStart();
             il.append(classGen.loadTranslet());
             il.append(new PUSH(cpg, Boolean.TRUE));
             il.append(new PUTFIELD(cpg.addFieldref(TRANSLET_CLASS,
                                                    HASIDCALL_INDEX,
                                                    HASIDCALL_INDEX_SIG)));
+            constructor.markChunkEnd();
         }
 
         // Compile in code to set the output configuration from <xsl:output>
         if (output != null) {
             // Set all the output settings files in the translet
+            constructor.markChunkStart();
             output.translate(classGen, constructor);
+            constructor.markChunkEnd();
         }
 
         // Compile default decimal formatting symbols.
         // This is an implicit, nameless xsl:decimal-format top-level element.
-        if (_numberFormattingUsed)
+        if (_numberFormattingUsed) {
+            constructor.markChunkStart();
             DecimalFormatting.translateDefaultDFS(classGen, constructor);
+            constructor.markChunkEnd();
+        }
 
         il.append(RETURN);
 
-        constructor.stripAttributes(true);
-        constructor.setMaxLocals();
-        constructor.setMaxStack();
-        classGen.addMethod(constructor.getMethod());
+        classGen.addMethod(constructor);
     }
 
     /**
@@ -1000,25 +1034,23 @@
 
         toplevel.addException("com.sun.org.apache.xalan.internal.xsltc.TransletException");
 
+        // Define and initialize 'current' variable with the root node
+        final LocalVariableGen current =
+            toplevel.addLocalVariable("current",
+                                      com.sun.org.apache.bcel.internal.generic.Type.INT,
+                                      null, null);
+
         final int setFilter = cpg.addInterfaceMethodref(DOM_INTF,
                                "setFilter",
                                "(Lcom/sun/org/apache/xalan/internal/xsltc/StripFilter;)V");
 
-        // Define and initialize 'current' variable with the root node
-        final LocalVariableGen current =
-            toplevel.addLocalVariable("current",
-                                    com.sun.org.apache.bcel.internal.generic.Type.INT,
-                                    il.getEnd(), null);
-
-        // Get root node from main DOM by calling dom.getIterator().next()
         final int gitr = cpg.addInterfaceMethodref(DOM_INTF,
-                                                   "getIterator", "()"+NODE_ITERATOR_SIG);
-        final int next = cpg.addInterfaceMethodref(NODE_ITERATOR,
-                                                   "next", "()I");
+                                                        "getIterator",
+                                                        "()"+NODE_ITERATOR_SIG);
         il.append(toplevel.loadDOM());
         il.append(new INVOKEINTERFACE(gitr, 1));
-        il.append(new INVOKEINTERFACE(next, 1));
-        il.append(new ISTORE(current.getIndex()));
+        il.append(toplevel.nextNode());
+        current.setStart(il.append(new ISTORE(current.getIndex())));
 
         // Create a new list containing variables/params + keys
         Vector varDepElements = new Vector(_globals);
@@ -1073,12 +1105,7 @@
         il.append(RETURN);
 
         // Compute max locals + stack and add method to class
-        toplevel.stripAttributes(true);
-        toplevel.setMaxLocals();
-        toplevel.setMaxStack();
-        toplevel.removeNOPs();
-
-        classGen.addMethod(toplevel.getMethod());
+        classGen.addMethod(toplevel);
 
         return("("+DOM_INTF_SIG+NODE_ITERATOR_SIG+TRANSLET_OUTPUT_SIG+")V");
     }
@@ -1233,7 +1260,7 @@
         final LocalVariableGen current =
             transf.addLocalVariable("current",
                                     com.sun.org.apache.bcel.internal.generic.Type.INT,
-                                    il.getEnd(), null);
+                                    null, null);
         final String applyTemplatesSig = classGen.getApplyTemplatesSig();
         final int applyTemplates = cpg.addMethodref(getClassName(),
                                                     "applyTemplates",
@@ -1270,6 +1297,15 @@
         //store to _dom variable
         il.append(new PUTFIELD(domField));
 
+        // continue with globals initialization
+        final int gitr = cpg.addInterfaceMethodref(DOM_INTF,
+                                                        "getIterator",
+                                                        "()"+NODE_ITERATOR_SIG);
+        il.append(transf.loadDOM());
+        il.append(new INVOKEINTERFACE(gitr, 1));
+        il.append(transf.nextNode());
+        current.setStart(il.append(new ISTORE(current.getIndex())));
+
         // Transfer the output settings to the output post-processor
         il.append(classGen.loadTranslet());
         il.append(transf.loadHandler());
@@ -1326,12 +1362,8 @@
         il.append(RETURN);
 
         // Compute max locals + stack and add method to class
-        transf.stripAttributes(true);
-        transf.setMaxLocals();
-        transf.setMaxStack();
-        transf.removeNOPs();
+        classGen.addMethod(transf);
 
-        classGen.addMethod(transf.getMethod());
     }
 
     /**
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/SymbolTable.java	Thu Apr 12 08:38:26 2012 -0700
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/SymbolTable.java	Tue Apr 17 11:17:59 2012 -0700
@@ -24,6 +24,7 @@
 package com.sun.org.apache.xalan.internal.xsltc.compiler;
 
 import java.util.Hashtable;
+import java.util.Stack;
 import java.util.StringTokenizer;
 import java.util.Vector;
 
@@ -46,6 +47,7 @@
     private Hashtable _attributeSets = null;
     private Hashtable _aliases = null;
     private Hashtable _excludedURI = null;
+    private Stack     _excludedURIStack = null;
     private Hashtable _decimalFormats = null;
     private Hashtable _keys = null;
 
@@ -158,7 +160,7 @@
     private int _nsCounter = 0;
 
     public String generateNamespacePrefix() {
-        return(new String("ns"+(_nsCounter++)));
+        return("ns"+(_nsCounter++));
     }
 
     /**
@@ -261,5 +263,33 @@
             }
         }
     }
+    /**
+     * Exclusion of namespaces by a stylesheet does not extend to any stylesheet
+     * imported or included by the stylesheet.  Upon entering the context of a
+     * new stylesheet, a call to this method is needed to clear the current set
+     * of excluded namespaces temporarily.  Every call to this method requires
+     * a corresponding call to {@link #popExcludedNamespacesContext()}.
+     */
+    public void pushExcludedNamespacesContext() {
+        if (_excludedURIStack == null) {
+            _excludedURIStack = new Stack();
+        }
+        _excludedURIStack.push(_excludedURI);
+        _excludedURI = null;
+    }
+
+    /**
+     * Exclusion of namespaces by a stylesheet does not extend to any stylesheet
+     * imported or included by the stylesheet.  Upon exiting the context of a
+     * stylesheet, a call to this method is needed to restore the set of
+     * excluded namespaces that was in effect prior to entering the context of
+     * the current stylesheet.
+     */
+    public void popExcludedNamespacesContext() {
+        _excludedURI = (Hashtable) _excludedURIStack.pop();
+        if (_excludedURIStack.isEmpty()) {
+            _excludedURIStack = null;
+        }
+    }
 
 }
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/SyntaxTreeNode.java	Thu Apr 12 08:38:26 2012 -0700
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/SyntaxTreeNode.java	Tue Apr 17 11:17:59 2012 -0700
@@ -512,9 +512,12 @@
                                      MethodGenerator methodGen) {
         // Call translate() on all child nodes
         final int n = elementCount();
+
         for (int i = 0; i < n; i++) {
+            methodGen.markChunkStart();
             final SyntaxTreeNode item = (SyntaxTreeNode)_contents.elementAt(i);
             item.translate(classGen, methodGen);
+            methodGen.markChunkEnd();
         }
 
         // After translation, unmap any registers for any variables/parameters
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/TestSeq.java	Thu Apr 12 08:38:26 2012 -0700
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/TestSeq.java	Tue Apr 17 11:17:59 2012 -0700
@@ -108,10 +108,10 @@
                 (LocationPathPattern) _patterns.elementAt(i);
 
             if (i == 0) {
-                result.append("Testseq for kernel " + _kernelType)
+                result.append("Testseq for kernel ").append(_kernelType)
                       .append('\n');
             }
-            result.append("   pattern " + i + ": ")
+            result.append("   pattern ").append(i).append(": ")
                   .append(pattern.toString())
                   .append('\n');
         }
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Variable.java	Thu Apr 12 08:38:26 2012 -0700
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Variable.java	Tue Apr 17 11:17:59 2012 -0700
@@ -28,6 +28,7 @@
 import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
 import com.sun.org.apache.bcel.internal.generic.DCONST;
 import com.sun.org.apache.bcel.internal.generic.ICONST;
+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.PUTFIELD;
 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.BooleanType;
@@ -128,7 +129,7 @@
             if (_local == null) {
                 _local = methodGen.addLocalVariable2(getEscapedName(),
                                                      _type.toJCType(),
-                                                     il.getEnd());
+                                                     null);
             }
             // Push the default value on the JVM's stack
             if ((_type instanceof IntType) ||
@@ -139,7 +140,10 @@
                 il.append(new DCONST(0)); // 0.0 for floating point numbers
             else
                 il.append(new ACONST_NULL()); // and 'null' for anything else
-            il.append(_type.STORE(_local.getIndex()));
+
+            // Mark the store as the start of the live range of the variable
+            _local.setStart(il.append(_type.STORE(_local.getIndex())));
+
         }
     }
 
@@ -163,10 +167,20 @@
             translateValue(classGen, methodGen);
 
             // Add a new local variable and store value
-            if (_local == null) {
+            boolean createLocal = _local == null;
+            if (createLocal) {
                 mapRegister(methodGen);
             }
+            InstructionHandle storeInst =
             il.append(_type.STORE(_local.getIndex()));
+
+            // If the local is just being created, mark the store as the start
+            // of its live range.  Note that it might have been created by
+            // initializeVariables already, which would have set the start of
+            // the live range already.
+            if (createLocal) {
+                _local.setStart(storeInst);
+        }
         }
         else {
             String signature = _type.toSignature();
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/VariableBase.java	Thu Apr 12 08:38:26 2012 -0700
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/VariableBase.java	Tue Apr 17 11:17:59 2012 -0700
@@ -84,14 +84,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);
-    }
-
-    /**
      * When a variable is overriden by another, e.g. via xsl:import,
      * its references need to be copied or otherwise it may be
      * compiled away as dead code. This method can be used for that
@@ -121,7 +113,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;
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/VariableRef.java	Thu Apr 12 08:38:26 2012 -0700
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/VariableRef.java	Tue Apr 17 11:17:59 2012 -0700
@@ -70,12 +70,10 @@
                 }
                 else {
                     il.append(_variable.loadInstruction());
-                    _variable.removeReference(this);
                 }
             }
             else {
                 il.append(_variable.loadInstruction());
-                _variable.removeReference(this);
             }
         }
         else {
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Whitespace.java	Thu Apr 12 08:38:26 2012 -0700
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/Whitespace.java	Tue Apr 17 11:17:59 2012 -0700
@@ -157,8 +157,7 @@
             if (col != -1) {
                 namespace = lookupNamespace(token.substring(0,col));
                 if (namespace != null) {
-                    elements.append(namespace+":"+
-                                    token.substring(col+1,token.length()));
+                    elements.append(namespace).append(':').append(token.substring(col + 1));
                 } else {
                     elements.append(token);
                 }
@@ -426,12 +425,7 @@
             compileStripSpace(strip, sCount, il);
         }
 
-        stripSpace.stripAttributes(true);
-        stripSpace.setMaxLocals();
-        stripSpace.setMaxStack();
-        stripSpace.removeNOPs();
-
-        classGen.addMethod(stripSpace.getMethod());
+        classGen.addMethod(stripSpace);
     }
 
     /**
@@ -463,12 +457,7 @@
             il.append(ICONST_0);
         il.append(IRETURN);
 
-        stripSpace.stripAttributes(true);
-        stripSpace.setMaxLocals();
-        stripSpace.setMaxStack();
-        stripSpace.removeNOPs();
-
-        classGen.addMethod(stripSpace.getMethod());
+        classGen.addMethod(stripSpace);
     }
 
 
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/XSLTC.java	Thu Apr 12 08:38:26 2012 -0700
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/XSLTC.java	Tue Apr 17 11:17:59 2012 -0700
@@ -131,11 +131,13 @@
      */
     private boolean _isSecureProcessing = false;
 
+    private boolean _useServicesMechanism = true;
+
     /**
      * XSLTC compiler constructor
      */
-    public XSLTC() {
-        _parser = new Parser(this);
+    public XSLTC(boolean useServicesMechanism) {
+        _parser = new Parser(this, useServicesMechanism);
     }
 
     /**
@@ -151,6 +153,19 @@
     public boolean isSecureProcessing() {
         return _isSecureProcessing;
     }
+    /**
+     * Return the state of the services mechanism feature.
+     */
+    public boolean useServicesMechnism() {
+        return _useServicesMechanism;
+    }
+
+    /**
+     * Set the state of the services mechanism feature.
+     */
+    public void setServicesMechnism(boolean flag) {
+        _useServicesMechanism = flag;
+    }
 
     /**
      * Only for user by the internal TrAX implementation.
@@ -230,6 +245,12 @@
     public void setTemplateInlining(boolean templateInlining) {
         _templateInlining = templateInlining;
     }
+     /**
+     * Return the state of the template inlining feature.
+     */
+    public boolean getTemplateInlining() {
+        return _templateInlining;
+    }
 
     /**
      * Set the parameters to use to locate the correct <?xml-stylesheet ...?>
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/XslAttribute.java	Thu Apr 12 08:38:26 2012 -0700
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/XslAttribute.java	Tue Apr 17 11:17:59 2012 -0700
@@ -209,13 +209,14 @@
 
         if (!_isLiteral) {
             // if the qname is an AVT, then the qname has to be checked at runtime if it is a valid qname
-            LocalVariableGen nameValue = methodGen.addLocalVariable2("nameValue",
+            LocalVariableGen nameValue =
+                    methodGen.addLocalVariable2("nameValue",
                     Util.getJCRefType(STRING_SIG),
-                    il.getEnd());
+                                                null);
 
             // store the name into a variable first so _name.translate only needs to be called once
             _name.translate(classGen, methodGen);
-            il.append(new ASTORE(nameValue.getIndex()));
+            nameValue.setStart(il.append(new ASTORE(nameValue.getIndex())));
             il.append(new ALOAD(nameValue.getIndex()));
 
             // call checkQName if the name is an AVT
@@ -230,7 +231,7 @@
             il.append(DUP);     // first arg to "attributes" call
 
             // load name value again
-            il.append(new ALOAD(nameValue.getIndex()));
+            nameValue.setEnd(il.append(new ALOAD(nameValue.getIndex())));
         } else {
             // Save the current handler base on the stack
             il.append(methodGen.loadHandler());
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/XslElement.java	Thu Apr 12 08:38:26 2012 -0700
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/XslElement.java	Tue Apr 17 11:17:59 2012 -0700
@@ -224,13 +224,14 @@
         if (!_ignore) {
 
             // if the qname is an AVT, then the qname has to be checked at runtime if it is a valid qname
-            LocalVariableGen nameValue = methodGen.addLocalVariable2("nameValue",
-                    Util.getJCRefType(STRING_SIG),
-                    il.getEnd());
+            LocalVariableGen nameValue =
+                    methodGen.addLocalVariable2("nameValue",
+                                                Util.getJCRefType(STRING_SIG),
+                                                null);
 
             // store the name into a variable first so _name.translate only needs to be called once
             _name.translate(classGen, methodGen);
-            il.append(new ASTORE(nameValue.getIndex()));
+            nameValue.setStart(il.append(new ASTORE(nameValue.getIndex())));
             il.append(new ALOAD(nameValue.getIndex()));
 
             // call checkQName if the name is an AVT
@@ -244,7 +245,7 @@
             il.append(methodGen.loadHandler());
 
             // load name value again
-            il.append(new ALOAD(nameValue.getIndex()));
+            nameValue.setEnd(il.append(new ALOAD(nameValue.getIndex())));
 
             if (_namespace != null) {
                 _namespace.translate(classGen, methodGen);
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/util/ClassGenerator.java	Thu Apr 12 08:38:26 2012 -0700
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/util/ClassGenerator.java	Tue Apr 17 11:17:59 2012 -0700
@@ -23,6 +23,7 @@
 
 package com.sun.org.apache.xalan.internal.xsltc.compiler.util;
 
+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.ClassGen;
 import com.sun.org.apache.bcel.internal.generic.Instruction;
@@ -134,4 +135,10 @@
     public boolean isExternal() {
         return false;
     }
+    public void addMethod(MethodGenerator methodGen) {
+        Method[] methodsToAdd = methodGen.getGeneratedMethods(this);
+        for (int i = 0; i < methodsToAdd.length; i++) {
+            addMethod(methodsToAdd[i]);
 }
+    }
+}
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/util/ErrorMessages.java	Thu Apr 12 08:38:26 2012 -0700
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/util/ErrorMessages.java	Tue Apr 17 11:17:59 2012 -0700
@@ -941,7 +941,64 @@
         "Cannot set the feature ''{0}'' on this TransformerFactory."},
 
         {ErrorMsg.JAXP_SECUREPROCESSING_FEATURE,
-        "FEATURE_SECURE_PROCESSING: Cannot set the feature to false when security manager is present."}
+        "FEATURE_SECURE_PROCESSING: Cannot set the feature to false when security manager is present."},
+
+        /*
+         * Note to translators:  This message describes an internal error in the
+         * processor.  The term "byte code" is a Java technical term for the
+         * executable code in a Java method, and "try-catch-finally block"
+         * refers to the Java keywords with those names.  "Outlined" is a
+         * technical term internal to XSLTC and should not be translated.
+         */
+        {ErrorMsg.OUTLINE_ERR_TRY_CATCH,
+         "Internal XSLTC error:  the generated byte code contains a " +
+         "try-catch-finally block and cannot be outlined."},
+
+        /*
+         * Note to translators:  This message describes an internal error in the
+         * processor.  The terms "OutlineableChunkStart" and
+         * "OutlineableChunkEnd" are the names of classes internal to XSLTC and
+         * should not be translated.  The message indicates that for every
+         * "start" there must be a corresponding "end", and vice versa, and
+         * that if one of a pair of "start" and "end" appears between another
+         * pair of corresponding "start" and "end", then the other half of the
+         * pair must also be between that same enclosing pair.
+         */
+        {ErrorMsg.OUTLINE_ERR_UNBALANCED_MARKERS,
+         "Internal XSLTC error:  OutlineableChunkStart and " +
+         "OutlineableChunkEnd markers must be balanced and properly nested."},
+
+        /*
+         * Note to translators:  This message describes an internal error in the
+         * processor.  The term "byte code" is a Java technical term for the
+         * executable code in a Java method.  The "method" that is being
+         * referred to is a Java method in a translet that XSLTC is generating
+         * in processing a stylesheet.  The "instruction" that is being
+         * referred to is one of the instrutions in the Java byte code in that
+         * method.  "Outlined" is a technical term internal to XSLTC and
+         * should not be translated.
+         */
+        {ErrorMsg.OUTLINE_ERR_DELETED_TARGET,
+         "Internal XSLTC error:  an instruction that was part of a block of " +
+         "byte code that was outlined is still referred to in the original " +
+         "method."
+        },
+
+
+        /*
+         * Note to translators:  This message describes an internal error in the
+         * processor.  The "method" that is being referred to is a Java method
+         * in a translet that XSLTC is generating.
+         *
+         */
+        {ErrorMsg.OUTLINE_ERR_METHOD_TOO_BIG,
+         "Internal XSLTC error:  a method in the translet exceeds the Java " +
+         "Virtual Machine limitation on the length of a method of 64 " +
+         "kilobytes.  This is usually caused by templates in a stylesheet " +
+         "that are very large.  Try restructuring your stylesheet to use " +
+         "smaller templates."
+        }
+
     };
 
     /** Get the lookup table for error messages.
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/util/ErrorMsg.java	Thu Apr 12 08:38:26 2012 -0700
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/util/ErrorMsg.java	Tue Apr 17 11:17:59 2012 -0700
@@ -157,6 +157,14 @@
     public static final String INVALID_NCNAME_ERR = "INVALID_NCNAME_ERR";
     public static final String INVALID_METHOD_IN_OUTPUT = "INVALID_METHOD_IN_OUTPUT";
 
+    public static final String OUTLINE_ERR_TRY_CATCH = "OUTLINE_ERR_TRY_CATCH";
+    public static final String OUTLINE_ERR_UNBALANCED_MARKERS =
+                                            "OUTLINE_ERR_UNBALANCED_MARKERS";
+    public static final String OUTLINE_ERR_DELETED_TARGET =
+                                            "OUTLINE_ERR_DELETED_TARGET";
+    public static final String OUTLINE_ERR_METHOD_TOO_BIG =
+                                            "OUTLINE_ERR_METHOD_TOO_BIG";
+
     // All error messages are localized and are stored in resource bundles.
     // This array and the following 4 strings are read from that bundle.
     private static ResourceBundle _bundle;
@@ -261,7 +269,7 @@
      */
     public String toString() {
         String suffix = (_params == null) ?
-            (null != _code ? new String(getErrorMessage()) : _message)
+            (null != _code ? getErrorMessage() : _message)
             : MessageFormat.format(getErrorMessage(), _params);
         return formatLine() + suffix;
     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/util/InternalError.java	Tue Apr 17 11:17:59 2012 -0700
@@ -0,0 +1,37 @@
+/*
+ * reserved comment block
+ * DO NOT REMOVE OR ALTER!
+ */
+/*
+ * Copyright 2001-2004 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.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * 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: InternalError.java,v 1.0 2011-08-18 04:34:19 joehw Exp $
+ */
+package com.sun.org.apache.xalan.internal.xsltc.compiler.util;
+/**
+ * Marks a class of errors in which XSLTC has reached some incorrect internal
+ * state from which it cannot recover.
+ */
+public class InternalError extends Error {
+    /**
+     * Construct an <code>InternalError</code> with the specified error message.
+     * @param msg the error message
+     */
+    public InternalError(String msg) {
+        super(msg);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/util/MarkerInstruction.java	Tue Apr 17 11:17:59 2012 -0700
@@ -0,0 +1,98 @@
+/*
+ * reserved comment block
+ * DO NOT REMOVE OR ALTER!
+ */
+/*
+ * Copyright 2001-2004 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.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * 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: MethodGenerator.java,v 1.10 2010-11-01 04:34:19 joehw Exp $
+ */
+package com.sun.org.apache.xalan.internal.xsltc.compiler.util;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
+import com.sun.org.apache.bcel.internal.Constants;
+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.Visitor;
+
+/**
+ * A special abstract dummy subclass of
+ * {@link org.apache.bcel.generic.Instruction} used to mark locations of
+ * interest in an {@link com.sun.org.apache.bcel.internal.generic.InstructionList}.  It and
+ * its subclasses are only used as placeholders, and do not contribute to the
+ * actual byte code instruction stream.
+ */
+abstract class MarkerInstruction extends Instruction {
+    /**
+     * Zero-argument constructor.  Sets the opcode to an invalid value and
+     * sets the length to zero, as it will not be written as part of the
+     * generated byte code.
+     */
+    public MarkerInstruction() {
+        super(Constants.UNDEFINED, (short) 0);
+    }
+
+    /**
+     * {@link com.sun.org.apache.bcel.internal.generic.Visitor}s will know nothing about this
+     * kind of {@link org.apche.bcel.generic.Instruction}, so this method does
+     * nothing.
+     */
+    public void accept(Visitor v) {
+    }
+
+    /**
+     * The number of JVM stack entries consumed by the instruction.
+     * This instruction is just a place holder, so it does not consume any
+     * stack entries.
+     * @param cpg The {@link com.sun.org.apache.bcel.internal.generic.ConstantPoolGen} for the
+     * current {@link com.sun.org.apache.bcel.internal.generic.ClassGen}
+     * @return <code>0</code> always
+     */
+    final public int consumeStack(ConstantPoolGen cpg) {
+        return 0;
+    }
+    /**
+     * The number of JVM stack entries produced by the instruction.
+     * This instruction is just a place holder, so it does not produce any
+     * stack entries.
+     * @param cpg The {@link com.sun.org.apache.bcel.internal.generic.ConstantPoolGen} for the
+     * current {@link com.sun.org.apache.bcel.internal.generic.ClassGen}
+     * @return <code>0</code> always
+     */
+    final public int produceStack(ConstantPoolGen cpg) {
+        return 0;
+    }
+
+    /**
+     * Produce a copy of the instruction.  By default a
+     * {@link MarkerInstruction} has no parameters, so the base implementation
+     * of {@link #copy()} returns the instruction itself.
+     * @return The instruction itself.
+     */
+    public Instruction copy() {
+        return this;
+    }
+    /**
+     * Dump instruction as byte code to stream out.  A {@link MarkerInstruction}
+     * has no effect on the generated byte code so it is never emitted to the
+     * output stream.
+     * @param out Output stream
+     */
+    final public void dump(DataOutputStream out) throws IOException {
+    }
+}
--- a/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/util/MethodGenerator.java	Thu Apr 12 08:38:26 2012 -0700
+++ b/jaxp/src/com/sun/org/apache/xalan/internal/xsltc/compiler/util/MethodGenerator.java	Tue Apr 17 11:17:59 2012 -0700
@@ -23,22 +23,57 @@
 
 package com.sun.org.apache.xalan.internal.xsltc.compiler.util;
 
-import java.util.Hashtable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+ import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Stack;
 
+
+import com.sun.org.apache.bcel.internal.Constants;
+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.ASTORE;
+import com.sun.org.apache.bcel.internal.generic.BranchHandle;
+import com.sun.org.apache.bcel.internal.generic.BranchInstruction;
 import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
+import com.sun.org.apache.bcel.internal.generic.DLOAD;
+import com.sun.org.apache.bcel.internal.generic.DSTORE;
+import com.sun.org.apache.bcel.internal.generic.FLOAD;
+import com.sun.org.apache.bcel.internal.generic.FSTORE;
+import com.sun.org.apache.bcel.internal.generic.GETFIELD;
+import com.sun.org.apache.bcel.internal.generic.GOTO;
 import com.sun.org.apache.bcel.internal.generic.ICONST;
+import com.sun.org.apache.bcel.internal.generic.IfInstruction;
 import com.sun.org.apache.bcel.internal.generic.ILOAD;
+import com.sun.org.apache.bcel.internal.generic.IndexedInstruction;
 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.ISTORE;
 import com.sun.org.apache.bcel.internal.generic.Instruction;
+import com.sun.org.apache.bcel.internal.generic.InstructionConstants;
 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.InstructionTargeter;
 import com.sun.org.apache.bcel.internal.generic.LocalVariableGen;
+import com.sun.org.apache.bcel.internal.generic.LocalVariableInstruction;
+import com.sun.org.apache.bcel.internal.generic.LLOAD;
+import com.sun.org.apache.bcel.internal.generic.LSTORE;
 import com.sun.org.apache.bcel.internal.generic.MethodGen;
+import com.sun.org.apache.bcel.internal.generic.NEW;
+import com.sun.org.apache.bcel.internal.generic.PUTFIELD;
+import com.sun.org.apache.bcel.internal.generic.RET;
+import com.sun.org.apache.bcel.internal.generic.Select;
+import com.sun.org.apache.bcel.internal.generic.TargetLostException;
 import com.sun.org.apache.bcel.internal.generic.Type;
+
 import com.sun.org.apache.xalan.internal.xsltc.compiler.Pattern;
+import com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC;
 
 /**
  * @author Jacek Ambroziak
@@ -59,6 +94,13 @@
     private static final int ITERATOR_INDEX  = 2;
     private static final int HANDLER_INDEX   = 3;
 
+    private static final int MAX_METHOD_SIZE = 65535;
+    private static final int MAX_BRANCH_TARGET_OFFSET = 32767;
+    private static final int MIN_BRANCH_TARGET_OFFSET = -32768;
+
+    private static final int TARGET_METHOD_SIZE = 60000;
+    private static final int MINIMUM_OUTLINEABLE_CHUNK_SIZE = 1000;
+
     private Instruction       _iloadCurrent;
     private Instruction       _istoreCurrent;
     private final Instruction _astoreHandler;
@@ -82,6 +124,7 @@
 
     private SlotAllocator _slotAllocator;
     private boolean _allocatorInit = false;
+    private LocalVariableRegistry _localVariableRegistry;
         /**
                  * A mapping between patterns and instruction lists used by
                  * test sequences to avoid compiling the same pattern multiple
@@ -168,7 +211,7 @@
         _nextNode = new INVOKEINTERFACE(index, 1);
 
         _slotAllocator = new SlotAllocator();
-        _slotAllocator.initialize(getLocalVariables());
+        _slotAllocator.initialize(getLocalVariableRegistry().getLocals(false));
         _allocatorInit = true;
     }
 
@@ -182,20 +225,364 @@
                                              InstructionHandle start,
                                              InstructionHandle end)
     {
-        return (_allocatorInit) ? addLocalVariable2(name, type, start)
-            : super.addLocalVariable(name, type, start, end);
+        LocalVariableGen lvg;
+
+        if (_allocatorInit) {
+            lvg = addLocalVariable2(name, type, start);
+        } else {
+            lvg = super.addLocalVariable(name, type, start, end);
+            getLocalVariableRegistry().registerLocalVariable(lvg);
+        }
+        return lvg;
     }
 
     public LocalVariableGen addLocalVariable2(String name, Type type,
                                               InstructionHandle start)
     {
-        return super.addLocalVariable(name, type,
-                                      _slotAllocator.allocateSlot(type),
-                                      start, null);
+        LocalVariableGen lvg = super.addLocalVariable(name, type,
+                                              _slotAllocator.allocateSlot(type),
+                                              start, null);
+        getLocalVariableRegistry().registerLocalVariable(lvg);
+        return lvg;
+    }
+    private LocalVariableRegistry getLocalVariableRegistry() {
+        if (_localVariableRegistry == null) {
+            _localVariableRegistry = new LocalVariableRegistry();
+        }
+
+        return _localVariableRegistry;
+    }
+
+    /**
+     * Keeps track of all local variables used in the method.
+     * <p>The
+     * {@link MethodGen#addLocalVariable(String,Type,InstructionHandle,InstructionHandle)}</code>
+     * and
+     * {@link MethodGen#addLocalVariable(String,Type,int,InstructionHandle,InstructionHandle)}</code>
+     * methods of {@link MethodGen} will only keep track of
+     * {@link LocalVariableGen} object until it'ss removed by a call to
+     * {@link MethodGen#removeLocalVariable(LocalVariableGen)}.</p>
+     * <p>In order to support efficient copying of local variables to outlined
+     * methods by
+     * {@link #outline(InstructionHandle,InstructionHandle,String,ClassGenerator)},
+     * this class keeps track of all local variables defined by the method.</p>
+     */
+    protected class LocalVariableRegistry {
+        /**
+         * <p>A <code>java.lang.ArrayList</code> of all
+         * {@link LocalVariableGen}s created for this method, indexed by the
+         * slot number of the local variable.  The JVM stack frame of local
+         * variables is divided into "slots".  A single slot can be used to
+         * store more than one variable in a method, without regard to type, so
+         * long as the byte code keeps the ranges of the two disjoint.</p>
+         * <p>If only one registration of use of a particular slot occurs, the
+         * corresponding entry of <code>_variables</code> contains the
+         * <code>LocalVariableGen</code>; if more than one occurs, the
+         * corresponding entry contains all such <code>LocalVariableGen</code>s
+         * registered for the same slot; and if none occurs, the entry will be
+         * <code>null</code>.
+         */
+        protected ArrayList _variables = new ArrayList();
+
+        /**
+         * Maps a name to a {@link LocalVariableGen}
+         */
+        protected HashMap _nameToLVGMap = new HashMap();
+
+        /**
+         * Registers a {@link org.apache.bcel.generic.LocalVariableGen}
+         * for this method.
+         * <p><b>Preconditions:</b>
+         * <ul>
+         * <li>The range of instructions for <code>lvg</code> does not
+         * overlap with the range of instructions for any
+         * <code>LocalVariableGen</code> with the same slot index previously
+         * registered for this method.  <b><em>(Unchecked.)</em></b></li>
+         * </ul></p>
+         * @param lvg The variable to be registered
+         */
+        protected void registerLocalVariable(LocalVariableGen lvg) {
+            int slot = lvg.getIndex();
+
+            int registrySize = _variables.size();
+
+            // If the LocalVariableGen uses a slot index beyond any previously
+            // encountered, expand the _variables, padding with intervening null
+            // entries as required.
+            if (slot >= registrySize) {
+                for (int i = registrySize; i < slot; i++) {
+                    _variables.add(null);
+                }
+                _variables.add(lvg);
+            } else {
+                // If the LocalVariableGen reuses a slot, make sure the entry
+                // in _variables contains an ArrayList and add the newly
+                // registered LocalVariableGen to the list.  If the entry in
+                // _variables just contains null padding, store the
+                // LocalVariableGen directly.
+                Object localsInSlot = _variables.get(slot);
+                if (localsInSlot != null) {
+                    if (localsInSlot instanceof LocalVariableGen) {
+                        ArrayList listOfLocalsInSlot = new ArrayList();
+                        listOfLocalsInSlot.add(localsInSlot);
+                        listOfLocalsInSlot.add(lvg);
+                        _variables.set(slot, listOfLocalsInSlot);
+                    } else {
+                        ((ArrayList) localsInSlot).add(lvg);
+                    }
+                } else {
+                    _variables.set(slot, lvg);
+                }
+            }
+
+            registerByName(lvg);
+        }
+
+        /**
+         * <p>Find which {@link LocalVariableGen}, if any, is registered for a
+         * particular JVM local stack frame slot at a particular position in the
+         * byte code for the method.</p>
+         * <p><b>Preconditions:</b>
+         * <ul>
+         * <li>The {@link InstructionList#setPositions()} has been called for
+         * the {@link InstructionList} associated with this
+         * {@link MethodGenerator}.</li>
+         * </ul></p>
+         * @param slot the JVM local stack frame slot number
+         * @param offset the position in the byte code
+         * @return the <code>LocalVariableGen</code> for the local variable
+         * stored in the relevant slot at the relevant offset; <code>null</code>
+         * if there is none.
+         */
+        protected LocalVariableGen lookupRegisteredLocalVariable(int slot,
+                                                                 int offset) {
+            Object localsInSlot = (_variables != null) ? _variables.get(slot)
+                                                       : null;
+
+            // If this slot index was never used, _variables.get will return
+            // null; if it was used once, it will return the LocalVariableGen;
+            // more than once it will return an ArrayList of all the
+            // LocalVariableGens for variables stored in that slot.  For each
+            // LocalVariableGen, check whether its range includes the
+            // specified offset, and return the first such encountered.
+            if (localsInSlot != null) {
+                if (localsInSlot instanceof LocalVariableGen) {
+                    LocalVariableGen lvg = (LocalVariableGen)localsInSlot;
+                    if (offsetInLocalVariableGenRange(lvg, offset)) {
+                        return lvg;
+                    }
+                } else {
+                    ArrayList listOfLocalsInSlot = (ArrayList) localsInSlot;
+                    int size = listOfLocalsInSlot.size();
+
+                    for (int i = 0; i < size; i++) {
+                        LocalVariableGen lvg =
+                            (LocalVariableGen)listOfLocalsInSlot.get(i);
+                        if (offsetInLocalVariableGenRange(lvg, offset)) {
+                            return lvg;
+                        }
+                    }
+                }
+            }
+
+            // No local variable stored in the specified slot at the specified
+            return null;
+        }
+
+        /**
+         * <p>Set up a mapping of the name of the specified
+         * {@link LocalVariableGen} object to the <code>LocalVariableGen</code>
+         * itself.</p>
+         * <p>This is a bit of a hack.  XSLTC is relying on the fact that the
+         * name that is being looked up won't be duplicated, which isn't
+         * guaranteed.  It replaces code which used to call
+         * {@link MethodGen#getLocalVariables()} and looped through the
+         * <code>LocalVariableGen</code> objects it contained to find the one
+         * with the specified name.  However, <code>getLocalVariables()</code>
+         * has the side effect of setting the start and end for any
+         * <code>LocalVariableGen</code> which did not already have them
+         * set, which causes problems for outlining..</p>
+         * <p>See also {@link #lookUpByName(String)} and
+         * {@link #removeByNameTracking(LocalVariableGen)}</P
+         * @param lvg a <code>LocalVariableGen</code>
+         */
+        protected void registerByName(LocalVariableGen lvg) {
+            Object duplicateNameEntry = _nameToLVGMap.get(lvg.getName());
+
+            if (duplicateNameEntry == null) {
+                _nameToLVGMap.put(lvg.getName(), lvg);
+            } else {
+                ArrayList sameNameList;
+
+                if (duplicateNameEntry instanceof ArrayList) {
+                    sameNameList = (ArrayList) duplicateNameEntry;
+                    sameNameList.add(lvg);
+                } else {
+                    sameNameList = new ArrayList();
+                    sameNameList.add(duplicateNameEntry);
+                    sameNameList.add(lvg);
+                }
+
+                _nameToLVGMap.put(lvg.getName(), sameNameList);
+            }
+        }
+
+        /**
+         * Remove the mapping from the name of the specified
+         * {@link LocalVariableGen} to itself.
+         * See also {@link #registerByName(LocalVariableGen)} and
+         * {@link #lookUpByName(String)}
+         * @param lvg a <code>LocalVariableGen</code>
+         */
+        protected void removeByNameTracking(LocalVariableGen lvg) {
+            Object duplicateNameEntry = _nameToLVGMap.get(lvg.getName());
+
+            if (duplicateNameEntry instanceof ArrayList) {
+                ArrayList sameNameList = (ArrayList) duplicateNameEntry;
+                for (int i = 0; i < sameNameList.size(); i++) {
+                    if (sameNameList.get(i) == lvg) {
+                        sameNameList.remove(i);
+                        break;
+                    }
+                }
+            } else {
+                _nameToLVGMap.remove(lvg);
+            }
+        }
+
+        /**
+         * <p>Given the name of a variable, finds a {@link LocalVariableGen}
+         * corresponding to it.</p>
+         * <p>See also {@link #registerByName(LocalVariableGen)} and
+         * {@link #removeByNameTracking(LocalVariableGen)}</p>
+         * @param name
+         * @return
+         */
+        protected LocalVariableGen lookUpByName(String name) {
+            LocalVariableGen lvg = null;
+            Object duplicateNameEntry = _nameToLVGMap.get(name);
+
+            if (duplicateNameEntry instanceof ArrayList) {
+                ArrayList sameNameList = (ArrayList) duplicateNameEntry;
+
+                for (int i = 0; i < sameNameList.size(); i++) {
+                    lvg = (LocalVariableGen)sameNameList.get(i);
+                    if (lvg.getName() == name) {
+                        break;
+                    }
+                }
+            } else {
+                lvg = (LocalVariableGen) duplicateNameEntry;
+            }
+
+            return lvg;
+        }
+
+        /**
+         * <p>Gets all {@link LocalVariableGen} objects for this method.</p>
+         * <p>When the <code>includeRemoved</code> argument has the value
+         * <code>false</code>, this method replaces uses of
+         * {@link MethodGen#getLocalVariables()} which has
+         * a side-effect of setting the start and end range for any
+         * <code>LocalVariableGen</code> if either was <code>null</code>.  That
+         * side-effect causes problems for outlining of code in XSLTC.
+         * @param includeRemoved Specifies whether all local variables ever
+         * declared should be returned (<code>true</code>) or only those not
+         * removed (<code>false</code>)
+         * @return an array of <code>LocalVariableGen</code> containing all the
+         * local variables
+         */
+        protected LocalVariableGen[] getLocals(boolean includeRemoved) {
+            LocalVariableGen[] locals = null;
+            ArrayList allVarsEverDeclared = new ArrayList();
+
+            if (includeRemoved) {
+                int slotCount = allVarsEverDeclared.size();
+
+                for (int i = 0; i < slotCount; i++) {
+                    Object slotEntries = _variables.get(i);
+                    if (slotEntries != null) {
+                        if (slotEntries instanceof ArrayList) {
+                            ArrayList slotList = (ArrayList) slotEntries;
+
+                            for (int j = 0; j < slotList.size(); j++) {
+                                allVarsEverDeclared.add(slotList.get(i));
+                            }
+                        } else {
+                            allVarsEverDeclared.add(slotEntries);
+                        }
+                    }
+                }
+            } else {
+                Iterator nameVarsPairsIter = _nameToLVGMap.entrySet().iterator();
+
+                while (nameVarsPairsIter.hasNext()) {
+                    Map.Entry nameVarsPair =
+                                  (Map.Entry) nameVarsPairsIter.next();
+                    Object vars = nameVarsPair.getValue();
+                    if (vars != null) {
+                        if (vars instanceof ArrayList) {
+                            ArrayList varsList = (ArrayList) vars;
+                            for (int i = 0; i < varsList.size(); i++) {
+                                allVarsEverDeclared.add(varsList.get(i));
+                            }
+                        } else {
+                            allVarsEverDeclared.add(vars);
+                        }
+                    }
+                }
+            }
+
+            locals = new LocalVariableGen[allVarsEverDeclared.size()];
+            allVarsEverDeclared.toArray(locals);
+
+            return locals;
+        }
+    }
+
+    /**
+     * Determines whether a particular variable is in use at a particular offset
+     * in the byte code for this method.
+     * <p><b>Preconditions:</b>
+     * <ul>
+     * <li>The {@link InstructionList#setPositions()} has been called for the
+     * {@link InstructionList} associated with this {@link MethodGenerator}.
+     * </li></ul></p>
+     * @param lvg the {@link LocalVariableGen} for the variable
+     * @param offset the position in the byte code
+     * @return <code>true</code> if and only if the specified variable is in
+     * use at the particular byte code offset.
+     */
+    boolean offsetInLocalVariableGenRange(LocalVariableGen lvg, int offset) {
+        InstructionHandle lvgStart = lvg.getStart();
+        InstructionHandle lvgEnd = lvg.getEnd();
+
+        // If no start handle is recorded for the LocalVariableGen, it is
+        // assumed to be in use from the beginning of the method.
+        if (lvgStart == null) {
+            lvgStart = getInstructionList().getStart();
+        }
+
+        // If no end handle is recorded for the LocalVariableGen, it is assumed
+        // to be in use to the end of the method.
+        if (lvgEnd == null) {
+            lvgEnd = getInstructionList().getEnd();
+        }
+
+        // Does the range of the instruction include the specified offset?
+        // Note that the InstructionHandle.getPosition method returns the
+        // offset of the beginning of an instruction.  A LocalVariableGen's
+        // range includes the end instruction itself, so that instruction's
+        // length must be taken into consideration in computing whether the
+        // varible is in range at a particular offset.
+        return ((lvgStart.getPosition() <= offset)
+                    && (lvgEnd.getPosition()
+                            + lvgEnd.getInstruction().getLength() >= offset));
     }
 
     public void removeLocalVariable(LocalVariableGen lvg) {
         _slotAllocator.releaseSlot(lvg);
+        getLocalVariableRegistry().removeByNameTracking(lvg);
         super.removeLocalVariable(lvg);
     }
 
@@ -294,11 +681,7 @@
     }
 
     public LocalVariableGen getLocalVariable(String name) {
-        final LocalVariableGen[] vars = getLocalVariables();
-        for (int i = 0; i < vars.length; i++)
-            if (vars[i].getName().equals(name))
-                return vars[i];
-        return null;
+        return getLocalVariableRegistry().lookUpByName(name);
     }
 
     public void setMaxLocals() {
@@ -320,21 +703,1447 @@
         super.setMaxLocals(maxLocals);
     }
 
+    /**
+     * Add a pre-compiled pattern to this mode.
+     */
+    public void addInstructionList(Pattern pattern, InstructionList ilist) {
+        _preCompiled.put(pattern, ilist);
+    }
+
+    /**
+     * Get the instruction list for a pre-compiled pattern. Used by
+     * test sequences to avoid compiling patterns more than once.
+     */
+    public InstructionList getInstructionList(Pattern pattern) {
+        return (InstructionList) _preCompiled.get(pattern);
+    }
+
+    /**
+     * Used to keep track of an outlineable chunk of instructions in the
+     * current method.  See {@link OutlineableChunkStart} and
+     * {@link OutlineableChunkEnd} for more information.
+     */
+    private class Chunk implements Comparable {
         /**
-         * Add a pre-compiled pattern to this mode.
+         * {@link InstructionHandle} of the first instruction in the outlineable
+         * chunk.
          */
-        public void addInstructionList(Pattern pattern,
-        InstructionList ilist)
-        {
-        _preCompiled.put(pattern, ilist);
+        private InstructionHandle m_start;
+
+        /**
+         * {@link org.apache.bcel.generic.InstructionHandle} of the first
+         * instruction in the outlineable chunk.
+         */
+        private InstructionHandle m_end;
+
+        /**
+         * Number of bytes in the instructions contained in this outlineable
+         * chunk.
+         */
+        private int m_size;
+
+        /**
+         * <p>Constructor for an outlineable {@link MethodGenerator.Chunk}.</p>
+         * <p><b>Preconditions:</b>
+         * <ul>
+         * <li>The {@link InstructionList#setPositions()} has been called for
+         * the {@link InstructionList} associated with this
+         * {@link MethodGenerator}.</li>
+         * </ul></p>
+         * @param start The {@link InstructionHandle} of the first
+         *              instruction in the outlineable chunk.
+         * @param end The {@link InstructionHandle} of the last
+         *            instruction in the outlineable chunk.
+         */
+        Chunk(InstructionHandle start, InstructionHandle end) {
+            m_start = start;
+            m_end = end;
+            m_size = end.getPosition() - start.getPosition();
         }
 
         /**
-         * Get the instruction list for a pre-compiled pattern. Used by
-         * test sequences to avoid compiling patterns more than once.
+         * Determines whether this outlineable {@link MethodGenerator.Chunk} is
+         * followed immediately by the argument
+         * <code>MethodGenerator.Chunk</code>, with no other intervening
+         * instructions, including {@link OutlineableChunkStart} or
+         * {@link OutlineableChunkEnd} instructions.
+         * @param neighbour an outlineable {@link MethodGenerator.Chunk}
+         * @return <code>true</code> if and only if the argument chunk
+         * immediately follows <code>this</code> chunk
          */
-        public InstructionList getInstructionList(Pattern pattern) {
-        return (InstructionList) _preCompiled.get(pattern);
+        boolean isAdjacentTo(Chunk neighbour) {
+            return getChunkEnd().getNext() == neighbour.getChunkStart();
         }
 
+        /**
+         * Getter method for the start of this {@linke MethodGenerator.Chunk}
+         * @return the {@link org.apache.bcel.generic.InstructionHandle} of the
+         * start of this chunk
+         */
+        InstructionHandle getChunkStart() {
+            return m_start;
+        }
+
+        /**
+         * Getter method for the end of this {@link MethodGenerator.Chunk}
+         * @return the {@link InstructionHandle} of the start of this chunk
+         */
+        InstructionHandle getChunkEnd() {
+            return m_end;
+        }
+
+        /**
+         * The size of this {@link MethodGenerator.Chunk}
+         * @return the number of bytes in the byte code represented by this
+         *         chunk.
+         */
+        int getChunkSize() {
+            return m_size;
+        }
+
+        /**
+         * Implements the <code>java.util.Comparable.compareTo(Object)</code>
+         * method.
+         * @return
+         * <ul>
+         * <li>A positive <code>int</code> if the length of <code>this</code>
+         * chunk in bytes is greater than that of <code>comparand</code></li>
+         * <li>A negative <code>int</code> if the length of <code>this</code>
+         * chunk in bytes is less than that of <code>comparand</code></li>
+         * <li>Zero, otherwise.</li>
+         * </ul>
+         */
+        public int compareTo(Object comparand) {
+            return getChunkSize() - ((Chunk)comparand).getChunkSize();
+        }
+    }
+
+    /**
+     * Find the outlineable chunks in this method that would be the best choices
+     * to outline, based on size and position in the method.
+     * @param classGen The {@link ClassGen} with which the generated methods
+     *                 will be associated
+     * @param totalMethodSize the size of the bytecode in the original method
+     * @return a <code>java.util.ArrayList</code> containing the
+     *  {@link MethodGenerator.Chunk}s that may be outlined from this method
+     */
+    private ArrayList getCandidateChunks(ClassGenerator classGen,
+                                         int totalMethodSize) {
+        Iterator instructions = getInstructionList().iterator();
+        ArrayList candidateChunks = new ArrayList();
+        ArrayList currLevelChunks = new ArrayList();
+        Stack subChunkStack = new Stack();
+        boolean openChunkAtCurrLevel = false;
+        boolean firstInstruction = true;
+
+        InstructionHandle currentHandle;
+
+        if (m_openChunks != 0) {
+            String msg =
+                (new ErrorMsg(ErrorMsg.OUTLINE_ERR_UNBALANCED_MARKERS))
+                    .toString();
+            throw new InternalError(msg);
+        }
+
+        // Scan instructions in the method, keeping track of the nesting level
+        // of outlineable chunks.
+        //
+        // currLevelChunks
+        //     keeps track of the child chunks of a chunk.  For each chunk,
+        //     there will be a pair of entries:  the InstructionHandles for the
+        //     start and for the end of the chunk
+        // subChunkStack
+        //     a stack containing the partially accumulated currLevelChunks for
+        //     each chunk that's still open at the current position in the
+        //     InstructionList.
+        // candidateChunks
+        //     the list of chunks which have been accepted as candidates chunks
+        //     for outlining
+        do {
+            // Get the next instruction.  The loop will perform one extra
+            // iteration after it reaches the end of the InstructionList, with
+            // currentHandle set to null.
+            currentHandle = instructions.hasNext()
+                                    ? (InstructionHandle) instructions.next()
+                                    : null;
+            Instruction inst =
+                    (currentHandle != null) ? currentHandle.getInstruction()
+                                            : null;
+
+            // At the first iteration, create a chunk representing all the
+            // code in the method.  This is done just to simplify the logic -
+            // this chunk can never be outlined because it will be too big.
+            if (firstInstruction) {
+                openChunkAtCurrLevel = true;
+                currLevelChunks.add(currentHandle);
+                firstInstruction = false;
+            }
+
+            // Found a new chunk
+            if (inst instanceof OutlineableChunkStart) {
+                // If last MarkerInstruction encountered was an
+                // OutlineableChunkStart, this represents the first chunk
+                // nested within that previous chunk - push the list of chunks
+                // from the outer level onto the stack
+                if (openChunkAtCurrLevel) {
+                    subChunkStack.push(currLevelChunks);
+                    currLevelChunks = new ArrayList();
+                }
+
+                openChunkAtCurrLevel = true;
+                currLevelChunks.add(currentHandle);
+            // Close off an open chunk
+            } else if (currentHandle == null
+                           || inst instanceof OutlineableChunkEnd) {
+                ArrayList nestedSubChunks = null;
+
+                // If the last MarkerInstruction encountered was an
+                // OutlineableChunkEnd, it means that the current instruction
+                // marks the end of a chunk that contained child chunks.
+                // Those children might need to be examined below in case they
+                // are better candidates for outlining than the current chunk.
+                if (!openChunkAtCurrLevel) {
+                    nestedSubChunks = currLevelChunks;
+                    currLevelChunks = (ArrayList)subChunkStack.pop();
+                }
+
+                // Get the handle for the start of this chunk (the last entry
+                // in currLevelChunks)
+                InstructionHandle chunkStart =
+                        (InstructionHandle) currLevelChunks.get(
+                                                      currLevelChunks.size()-1);
+
+                int chunkEndPosition =
+                        (currentHandle != null) ? currentHandle.getPosition()
+                                                : totalMethodSize;
+                int chunkSize = chunkEndPosition - chunkStart.getPosition();
+
+                // Two ranges of chunk size to consider:
+                //
+                // 1. [0,TARGET_METHOD_SIZE]
+                //      Keep this chunk in consideration as a candidate,
+                //      and ignore its subchunks, if any - there's nothing to be
+                //      gained by outlining both the current chunk and its
+                //      children!
+                //
+                // 2. (TARGET_METHOD_SIZE,+infinity)
+                //      Ignore this chunk - it's too big.  Add its subchunks
+                //      as candidates, after merging adjacent chunks to produce
+                //      chunks that are as large as possible
+                if (chunkSize <= TARGET_METHOD_SIZE) {
+                    currLevelChunks.add(currentHandle);
+                } else {
+                    if (!openChunkAtCurrLevel) {
+                        int childChunkCount = nestedSubChunks.size() / 2;
+                        if (childChunkCount > 0) {
+                            Chunk[] childChunks = new Chunk[childChunkCount];
+
+                            // Gather all the child chunks of the current chunk
+                            for (int i = 0; i < childChunkCount; i++) {
+                                InstructionHandle start =
+                                    (InstructionHandle) nestedSubChunks
+                                                            .get(i*2);
+                                InstructionHandle end =
+                                    (InstructionHandle) nestedSubChunks
+                                                            .get(i*2+1);
+
+                                childChunks[i] = new Chunk(start, end);
+                            }
+
+                            // Merge adjacent siblings
+                            ArrayList mergedChildChunks =
+                                        mergeAdjacentChunks(childChunks);
+
+                            // Add chunks that mean minimum size requirements
+                            // to the list of candidate chunks for outlining
+                            for (int i = 0; i < mergedChildChunks.size(); i++) {
+                                Chunk mergedChunk =
+                                    (Chunk)mergedChildChunks.get(i);
+                                int mergedSize = mergedChunk.getChunkSize();
+
+                                if (mergedSize >= MINIMUM_OUTLINEABLE_CHUNK_SIZE
+                                        && mergedSize <= TARGET_METHOD_SIZE) {
+                                    candidateChunks.add(mergedChunk);
+                                }
+                            }
+                        }
+                    }
+
+                    // Drop the chunk which was too big
+                    currLevelChunks.remove(currLevelChunks.size() - 1);
+                }
+
+                // currLevelChunks contains pairs of InstructionHandles.  If
+                // its size is an odd number, the loop has encountered the
+                // start of a chunk at this level, but not its end.
+                openChunkAtCurrLevel = ((currLevelChunks.size() & 0x1) == 1);
+            }
+
+        } while (currentHandle != null);
+
+        return candidateChunks;
+    }
+
+    /**
+     * Merge adjacent sibling chunks to produce larger candidate chunks for
+     * outlining
+     * @param chunks array of sibling {@link MethodGenerator.Chunk}s that are
+     *               under consideration for outlining.  Chunks must be in
+     *               the order encountered in the {@link InstructionList}
+     * @return a <code>java.util.ArrayList</code> of
+     *         <code>MethodGenerator.Chunk</code>s maximally merged
+     */
+    private ArrayList mergeAdjacentChunks(Chunk[] chunks) {
+        int[] adjacencyRunStart = new int[chunks.length];
+        int[] adjacencyRunLength = new int[chunks.length];
+        boolean[] chunkWasMerged = new boolean[chunks.length];
+
+        int maximumRunOfChunks = 0;
+        int startOfCurrentRun;
+        int numAdjacentRuns = 0;
+
+        ArrayList mergedChunks = new ArrayList();
+
+        startOfCurrentRun = 0;
+
+        // Loop through chunks, and record in adjacencyRunStart where each
+        // run of adjacent chunks begins and how many are in that run.  For
+        // example, given chunks A B C D E F, if A is adjacent to B, but not
+        // to C, and C, D, E and F are all adjacent,
+        //   adjacencyRunStart[0] == 0; adjacencyRunLength[0] == 2
+        //   adjacencyRunStart[1] == 2; adjacencyRunLength[1] == 4
+        for (int i = 1; i < chunks.length; i++) {
+            if (!chunks[i-1].isAdjacentTo(chunks[i])) {
+                int lengthOfRun = i - startOfCurrentRun;
+
+                // Track the longest run of chunks found
+                if (maximumRunOfChunks < lengthOfRun) {
+                    maximumRunOfChunks = lengthOfRun;
+                }
+
+                if (lengthOfRun > 1 ) {
+                    adjacencyRunLength[numAdjacentRuns] = lengthOfRun;
+                    adjacencyRunStart[numAdjacentRuns] = startOfCurrentRun;
+                    numAdjacentRuns++;
+                }
+
+                startOfCurrentRun = i;
+            }
+        }
+
+        if (chunks.length - startOfCurrentRun > 1) {
+            int lengthOfRun = chunks.length - startOfCurrentRun;
+
+            // Track the longest run of chunks found
+            if (maximumRunOfChunks < lengthOfRun) {
+                maximumRunOfChunks = lengthOfRun;
+            }
+
+            adjacencyRunLength[numAdjacentRuns] =
+                        chunks.length - startOfCurrentRun;
+            adjacencyRunStart[numAdjacentRuns] = startOfCurrentRun;
+            numAdjacentRuns++;
+        }
+
+        // Try merging adjacent chunks to come up with better sized chunks for
+        // outlining.  This algorithm is not optimal, but it should be
+        // reasonably fast.  Consider an example like this, where four chunks
+        // of the sizes specified in brackets are adjacent.  The best way of
+        // combining these chunks would be to merge the first pair and merge
+        // the last three to form two chunks, but the algorithm will merge the
+        // three in the middle instead, leaving three chunks in all.
+        //    [25000] [25000] [20000] [1000] [20000]
+
+        // Start by trying to merge the maximum number of adjacent chunks, and
+        // work down from there.
+        for (int numToMerge = maximumRunOfChunks; numToMerge>1; numToMerge--) {
+            // Look at each run of adjacent chunks
+            for (int run = 0; run < numAdjacentRuns; run++) {
+                int runStart = adjacencyRunStart[run];
+                int runEnd = runStart + adjacencyRunLength[run] - 1;
+
+                boolean foundChunksToMerge = false;
+
+                // Within the current run of adjacent chunks, look at all
+                // "subruns" of length numToMerge, until we run out or find
+                // a subrun that can be merged.
+                for (int mergeStart = runStart;
+                     mergeStart+numToMerge-1 <= runEnd && !foundChunksToMerge;
+                     mergeStart++) {
+                    int mergeEnd = mergeStart + numToMerge - 1;
+                    int mergeSize = 0;
+
+                    // Find out how big the subrun is
+                    for (int j = mergeStart; j <= mergeEnd; j++) {
+                        mergeSize = mergeSize + chunks[j].getChunkSize();
+                    }
+
+                    // If the current subrun is small enough to outline,
+                    // merge it, and split the remaining chunks in the run
+                    if (mergeSize <= TARGET_METHOD_SIZE) {
+                        foundChunksToMerge = true;
+
+                        for (int j = mergeStart; j <= mergeEnd; j++) {
+                            chunkWasMerged[j] = true;
+                        }
+
+                        mergedChunks.add(
+                                new Chunk(chunks[mergeStart].getChunkStart(),
+                                          chunks[mergeEnd].getChunkEnd()));
+
+                        // Adjust the length of the current run of adjacent
+                        // chunks to end at the newly merged chunk...
+                        adjacencyRunLength[run] =
+                                adjacencyRunStart[run] - mergeStart;
+
+                        int trailingRunLength = runEnd - mergeEnd;
+
+                        // and any chunks that follow the newly merged chunk
+                        // in the current run of adjacent chunks form another
+                        // new run of adjacent chunks
+                        if (trailingRunLength >= 2) {
+                            adjacencyRunStart[numAdjacentRuns] = mergeEnd + 1;
+                            adjacencyRunLength[numAdjacentRuns] =
+                                                            trailingRunLength;
+                            numAdjacentRuns++;
+                        }
+                    }
+                }
+            }
+        }
+
+        // Make a final pass for any chunk that wasn't merged with a sibling
+        // and include it in the list of chunks after merging.
+        for (int i = 0; i < chunks.length; i++) {
+            if (!chunkWasMerged[i]) {
+                mergedChunks.add(chunks[i]);
+            }
+        }
+
+        return mergedChunks;
+    }
+
+    /**
+     * Breaks up the IL for this {@link MethodGenerator} into separate
+     * outlined methods so that no method exceeds the 64KB limit on the length
+     * of the byte code associated with a method.
+     * @param classGen The {@link ClassGen} with which the generated methods
+     *                 will be associated
+     * @param originalMethodSize The number of bytes of bytecode represented by
+     *                 the {@link InstructionList} of this method
+     * @return an array of the outlined <code>Method</code>s and the original
+     *         method itself
+     */
+    public Method[] outlineChunks(ClassGenerator classGen,
+                                  int originalMethodSize) {
+        ArrayList methodsOutlined = new ArrayList();
+        int currentMethodSize = originalMethodSize;
+
+        int outlinedCount = 0;
+        boolean moreMethodsOutlined;
+        String originalMethodName = getName();
+
+        // Special handling for initialization methods.  No other methods can
+        // include the less than and greater than characters in their names,
+        // so we munge the names here.
+        if (originalMethodName.equals("<init>")) {
+            originalMethodName = "$lt$init$gt$";
+        } else if (originalMethodName.equals("<clinit>")) {
+            originalMethodName = "$lt$clinit$gt$";
+        }
+
+        // Loop until the original method comes in under the JVM limit or
+        // the loop was unable to outline any more methods
+        do {
+            // Get all the best candidates for outlining, and sort them in
+            // ascending order of size
+            ArrayList candidateChunks = getCandidateChunks(classGen,
+                                                           currentMethodSize);
+            Collections.sort(candidateChunks);
+
+            moreMethodsOutlined = false;
+
+            // Loop over the candidates for outlining, from the largest to the
+            // smallest and outline them one at a time, until the loop has
+            // outlined all or the original method comes in under the JVM
+            // limit on the size of a method.
+            for (int i = candidateChunks.size()-1;
+                 i >= 0 && currentMethodSize > TARGET_METHOD_SIZE;
+                 i--) {
+                Chunk chunkToOutline = (Chunk)candidateChunks.get(i);
+
+                methodsOutlined.add(outline(chunkToOutline.getChunkStart(),
+                                            chunkToOutline.getChunkEnd(),
+                                            originalMethodName + "$outline$"
+                                                               + outlinedCount,
+                                            classGen));
+                outlinedCount++;
+                moreMethodsOutlined = true;
+
+                InstructionList il = getInstructionList();
+                InstructionHandle lastInst = il.getEnd();
+                il.setPositions();
+
+                // Check the size of the method now
+                currentMethodSize =
+                        lastInst.getPosition()
+                                + lastInst.getInstruction().getLength();
+            }
+        } while (moreMethodsOutlined && currentMethodSize > TARGET_METHOD_SIZE);
+
+        // Outlining failed to reduce the size of the current method
+        // sufficiently.  Throw an internal error.
+        if (currentMethodSize > MAX_METHOD_SIZE) {
+            String msg = (new ErrorMsg(ErrorMsg.OUTLINE_ERR_METHOD_TOO_BIG))
+                                  .toString();
+            throw new InternalError(msg);
+        }
+
+        Method[] methodsArr = new Method[methodsOutlined.size() + 1];
+        methodsOutlined.toArray(methodsArr);
+
+        methodsArr[methodsOutlined.size()] = getThisMethod();
+
+        return methodsArr;
+    }
+
+    /**
+     * Given an outlineable chunk of code in the current {@link MethodGenerator}
+     * move ("outline") the chunk to a new method, and replace the chunk in the
+     * old method with a reference to that new method.  No
+     * {@link OutlineableChunkStart} or {@link OutlineableChunkEnd} instructions
+     * are copied.
+     * @param first The {@link InstructionHandle} of the first instruction in
+     *              the chunk to outline
+     * @param last The <code>InstructionHandle</code> of the last instruction in
+     *             the chunk to outline
+     * @param outlinedMethodName The name of the new method
+     * @param classGen The {@link ClassGenerator} of which the original
+     *              and new methods will be members
+     * @return The new {@link Method} containing the outlined code.
+     */
+    private Method outline(InstructionHandle first, InstructionHandle last,
+                           String outlinedMethodName, ClassGenerator classGen) {
+        // We're not equipped to deal with exception handlers yet.  Bail out!
+        if (getExceptionHandlers().length != 0) {
+            String msg = (new ErrorMsg(ErrorMsg.OUTLINE_ERR_TRY_CATCH))
+                                  .toString();
+            throw new InternalError(msg);
+        }
+
+        int outlineChunkStartOffset = first.getPosition();
+        int outlineChunkEndOffset = last.getPosition()
+                                        + last.getInstruction().getLength();
+
+        ConstantPoolGen cpg = getConstantPool();
+
+        // Create new outlined method with signature:
+        //
+        //   private final outlinedMethodName(CopyLocals copyLocals);
+        //
+        // CopyLocals is an object that is used to copy-in/copy-out local
+        // variables that are used by the outlined method.   Only locals whose
+        // value is potentially set or referenced outside the range of the
+        // chunk that is being outlined will be represented in CopyLocals.  The
+        // type of the variable for copying local variables is actually
+        // generated to be unique - it is not named CopyLocals.
+        //
+        // The outlined method never needs to be referenced outside of this
+        // class, and will never be overridden, so we mark it private final.
+        final InstructionList newIL = new InstructionList();
+
+        final XSLTC  xsltc = classGen.getParser().getXSLTC();
+        final String argTypeName = xsltc.getHelperClassName();
+        final Type[] argTypes =
+            new Type[] {(new ObjectType(argTypeName)).toJCType()};
+        final String argName = "copyLocals";
+        final String[] argNames = new String[] {argName};
+
+        int methodAttributes = ACC_PRIVATE | ACC_FINAL;
+        final boolean isStaticMethod = (getAccessFlags() & ACC_STATIC) != 0;
+
+        if (isStaticMethod) {
+            methodAttributes = methodAttributes | ACC_STATIC;
+        }
+
+        final MethodGenerator outlinedMethodGen =
+            new MethodGenerator(methodAttributes,
+                                com.sun.org.apache.bcel.internal.generic.Type.VOID,
+                                argTypes, argNames, outlinedMethodName,
+                                getClassName(), newIL, cpg);
+
+        // Create class for copying local variables to the outlined method.
+        // The fields the class will need to contain will be determined as the
+        // code in the outlineable chunk is examined.
+        ClassGenerator copyAreaCG
+            = new ClassGenerator(argTypeName, OBJECT_CLASS, argTypeName+".java",
+                                 ACC_FINAL | ACC_PUBLIC | ACC_SUPER, null,
+                                 classGen.getStylesheet()) {
+                      public boolean isExternal() {
+                          return true;
+                      }
+                  };
+        ConstantPoolGen copyAreaCPG = copyAreaCG.getConstantPool();
+        copyAreaCG.addEmptyConstructor(ACC_PUBLIC);
+
+        // Number of fields in the copy class
+        int copyAreaFieldCount = 0;
+
+        // The handle for the instruction after the last one to be outlined.
+        // Note that this should never end up being null.  An outlineable chunk
+        // won't contain a RETURN instruction or other branch out of the chunk,
+        // and the JVM specification prohibits code in a method from just
+        // "falling off the end" so this should always point to a valid handle.
+        InstructionHandle limit = last.getNext();
+
+        // InstructionLists for copying values into and out of an instance of
+        // CopyLocals:
+        //      oldMethCoypInIL  - from locals in old method into an instance
+        //                         of the CopyLocals class (oldMethCopyInIL)
+        //      oldMethCopyOutIL - from CopyLocals back into locals in the old
+        //                         method
+        //      newMethCopyInIL  - from CopyLocals into locals in the new
+        //                         method
+        //      newMethCopyOutIL - from locals in new method into the instance
+        //                         of the CopyLocals class
+        InstructionList oldMethCopyInIL  = new InstructionList();
+        InstructionList oldMethCopyOutIL = new InstructionList();
+        InstructionList newMethCopyInIL  = new InstructionList();
+        InstructionList newMethCopyOutIL = new InstructionList();
+
+        // Allocate instance of class in which we'll copy in or copy out locals
+        // and make two copies:  last copy is used to invoke constructor;
+        // other two are used for references to fields in the CopyLocals object
+        InstructionHandle outlinedMethodCallSetup =
+            oldMethCopyInIL.append(new NEW(cpg.addClass(argTypeName)));
+        oldMethCopyInIL.append(InstructionConstants.DUP);
+        oldMethCopyInIL.append(InstructionConstants.DUP);
+        oldMethCopyInIL.append(
+            new INVOKESPECIAL(cpg.addMethodref(argTypeName, "<init>", "()V")));
+
+        // Generate code to invoke the new outlined method, and place the code
+        // on oldMethCopyOutIL
+        InstructionHandle outlinedMethodRef;
+
+        if (isStaticMethod) {
+            outlinedMethodRef =
+                oldMethCopyOutIL.append(
+                    new INVOKESTATIC(cpg.addMethodref(
+                                          classGen.getClassName(),
+                                          outlinedMethodName,
+                                          outlinedMethodGen.getSignature())));
+        } else {
+            oldMethCopyOutIL.append(InstructionConstants.THIS);
+            oldMethCopyOutIL.append(InstructionConstants.SWAP);
+            outlinedMethodRef =
+                oldMethCopyOutIL.append(
+                    new INVOKEVIRTUAL(cpg.addMethodref(
+                                          classGen.getClassName(),
+                                          outlinedMethodName,
+                                          outlinedMethodGen.getSignature())));
+        }
+
+        // Used to keep track of the first in a sequence of
+        // OutlineableChunkStart instructions
+        boolean chunkStartTargetMappingsPending = false;
+        InstructionHandle pendingTargetMappingHandle = null;
+
+        // Used to keep track of the last instruction that was copied
+        InstructionHandle lastCopyHandle = null;
+
+        // Keeps track of the mapping from instruction handles in the old
+        // method to instruction handles in the outlined method.  Only need
+        // to track instructions that are targeted by something else in the
+        // generated BCEL
+        HashMap targetMap   = new HashMap();
+
+        // Keeps track of the mapping from local variables in the old method
+        // to local variables in the outlined method.
+        HashMap localVarMap = new HashMap();
+
+        HashMap revisedLocalVarStart = new HashMap();
+        HashMap revisedLocalVarEnd = new HashMap();
+
+        // Pass 1: Make copies of all instructions, append them to the new list
+        // and associate old instruction references with the new ones, i.e.,
+        // a 1:1 mapping.  The special marker instructions are not copied.
+        // Also, identify local variables whose values need to be copied into or
+        // out of the new outlined method, and builds up targetMap and
+        // localVarMap as described above.  The code identifies those local
+        // variables first so that they can have fixed slots in the stack
+        // frame for the outlined method assigned them ahead of all those
+        // variables that don't need to exist for the entirety of the outlined
+        // method invocation.
+        for (InstructionHandle ih = first; ih != limit; ih = ih.getNext()) {
+            Instruction inst = ih.getInstruction();
+
+            // MarkerInstructions are not copied, so if something else targets
+            // one, the targetMap will point to the nearest copied sibling
+            // InstructionHandle:  for an OutlineableChunkEnd, the nearest
+            // preceding sibling; for an OutlineableChunkStart, the nearest
+            // following sibling.
+            if (inst instanceof MarkerInstruction) {
+                if (ih.hasTargeters()) {
+                    if (inst instanceof OutlineableChunkEnd) {
+                        targetMap.put(ih, lastCopyHandle);
+                    } else {
+                        if (!chunkStartTargetMappingsPending)  {
+                            chunkStartTargetMappingsPending = true;
+                            pendingTargetMappingHandle = ih;
+                        }
+                    }
+                }
+            } else {
+                // Copy the instruction and append it to the outlined method's
+                // InstructionList.
+                Instruction c = inst.copy(); // Use clone for shallow copy
+
+                if (c instanceof BranchInstruction) {
+                    lastCopyHandle = newIL.append((BranchInstruction)c);
+                } else {
+                    lastCopyHandle = newIL.append(c);
+                }
+
+                if (c instanceof LocalVariableInstruction
+                        || c instanceof RET) {
+                    // For any instruction that touches a local variable,
+                    // check whether the local variable's value needs to be
+                    // copied into or out of the outlined method.  If so,
+                    // generate the code to perform the necessary copying, and
+                    // use localVarMap to map the variable in the original
+                    // method to the variable in the new method.
+                    IndexedInstruction lvi = (IndexedInstruction)c;
+                    int oldLocalVarIndex = lvi.getIndex();
+                    LocalVariableGen oldLVG =
+                            getLocalVariableRegistry()
+                                .lookupRegisteredLocalVariable(oldLocalVarIndex,
+                                                              ih.getPosition());
+                    LocalVariableGen newLVG =
+                            (LocalVariableGen)localVarMap.get(oldLVG);
+
+                    // Has the code already mapped this local variable to a
+                    // local in the new method?
+                    if (localVarMap.get(oldLVG) == null) {
+                        // Determine whether the local variable needs to be
+                        // copied into or out of the outlined by checking
+                        // whether the range of instructions in which the
+                        // variable is accessible is outside the range of
+                        // instructions in the outlineable chunk.
+                        // Special case a chunk start offset of zero:  a local
+                        // variable live at that position must be a method
+                        // parameter, so the code doesn't need to check whether
+                        // the variable is live before that point; being live
+                        // at offset zero is sufficient to know that the value
+                        // must be copied in to the outlined method.
+                        boolean copyInLocalValue =
+                            offsetInLocalVariableGenRange(oldLVG,
+                                                (outlineChunkStartOffset != 0)
+                                                    ? outlineChunkStartOffset-1
+                                                    : 0);
+                        boolean copyOutLocalValue =
+                            offsetInLocalVariableGenRange(oldLVG,
+                                                outlineChunkEndOffset+1);
+
+                        // For any variable that needs to be copied into or out
+                        // of the outlined method, create a field in the
+                        // CopyLocals class, and generate the necessary code for
+                        // copying the value.
+                        if (copyInLocalValue || copyOutLocalValue) {
+                            String varName = oldLVG.getName();
+                            Type varType = oldLVG.getType();
+                            newLVG = outlinedMethodGen.addLocalVariable(varName,
+                                                                        varType,
+                                                                        null,
+                                                                        null);
+                            int newLocalVarIndex = newLVG.getIndex();
+                            String varSignature = varType.getSignature();
+
+                            // Record the mapping from the old local to the new
+                            localVarMap.put(oldLVG, newLVG);
+
+                            copyAreaFieldCount++;
+                            String copyAreaFieldName =
+                                           "field" + copyAreaFieldCount;
+                            copyAreaCG.addField(
+                                new Field(ACC_PUBLIC,
+                                        copyAreaCPG.addUtf8(copyAreaFieldName),
+                                        copyAreaCPG.addUtf8(varSignature),
+                                        null, copyAreaCPG.getConstantPool()));
+
+                            int fieldRef = cpg.addFieldref(argTypeName,
+                                                           copyAreaFieldName,
+                                                           varSignature);
+
+                            if (copyInLocalValue) {
+                                // Generate code for the old method to store the
+                                // value of the local into the correct field in
+                                // CopyLocals prior to invocation of the
+                                // outlined method.
+                                oldMethCopyInIL.append(
+                                        InstructionConstants.DUP);
+                                InstructionHandle copyInLoad =
+                                    oldMethCopyInIL.append(
+                                        loadLocal(oldLocalVarIndex, varType));
+                                oldMethCopyInIL.append(new PUTFIELD(fieldRef));
+
+                                // If the end of the live range of the old
+                                // variable was in the middle of the outlined
+                                // chunk.  Make the load of its value the new
+                                // end of its range.
+                                if (!copyOutLocalValue) {
+                                    revisedLocalVarEnd.put(oldLVG, copyInLoad);
+                                }
+
+                                // Generate code for start of the outlined
+                                // method to copy the value from a field in
+                                // CopyLocals to the new local in the outlined
+                                // method
+                                newMethCopyInIL.append(
+                                        InstructionConstants.ALOAD_1);
+                                newMethCopyInIL.append(new GETFIELD(fieldRef));
+                                newMethCopyInIL.append(
+                                        storeLocal(newLocalVarIndex, varType));
+                            }
+
+                            if (copyOutLocalValue) {
+                                // Generate code for the end of the outlined
+                                // method to copy the value from the new local
+                                // variable into a field in CopyLocals
+                                // method
+                                newMethCopyOutIL.append(
+                                        InstructionConstants.ALOAD_1);
+                                newMethCopyOutIL.append(
+                                        loadLocal(newLocalVarIndex, varType));
+                                newMethCopyOutIL.append(new PUTFIELD(fieldRef));
+
+                                // Generate code to copy the value from a field
+                                // in CopyLocals into a local in the original
+                                // method following invocation of the outlined
+                                // method.
+                                oldMethCopyOutIL.append(
+                                        InstructionConstants.DUP);
+                                oldMethCopyOutIL.append(new GETFIELD(fieldRef));
+                                InstructionHandle copyOutStore =
+                                    oldMethCopyOutIL.append(
+                                        storeLocal(oldLocalVarIndex, varType));
+
+                                // If the start of the live range of the old
+                                // variable was in the middle of the outlined
+                                // chunk.  Make this store into it the new start
+                                // of its range.
+                                if (!copyInLocalValue) {
+                                    revisedLocalVarStart.put(oldLVG,
+                                                             copyOutStore);
+                                }
+                            }
+                        }
+                    }
+                }
+
+                if (ih.hasTargeters()) {
+                    targetMap.put(ih, lastCopyHandle);
+                }
+
+                // If this is the first instruction copied following a sequence
+                // of OutlineableChunkStart instructions, indicate that the
+                // sequence of old instruction all map to this newly created
+                // instruction
+                if (chunkStartTargetMappingsPending) {
+                    do {
+                         targetMap.put(pendingTargetMappingHandle,
+                                       lastCopyHandle);
+                         pendingTargetMappingHandle =
+                                 pendingTargetMappingHandle.getNext();
+                    } while(pendingTargetMappingHandle != ih);
+
+                    chunkStartTargetMappingsPending = false;
+                }
+            }
+        }
+
+        // Pass 2: Walk old and new instruction lists, updating branch targets
+        // and local variable references in the new list
+        InstructionHandle ih = first;
+        InstructionHandle ch = newIL.getStart();
+
+        while (ch != null) {
+            // i == old instruction; c == copied instruction
+            Instruction i = ih.getInstruction();
+            Instruction c = ch.getInstruction();
+
+            if (i instanceof BranchInstruction) {
+                BranchInstruction bc      = (BranchInstruction)c;
+                BranchInstruction bi      = (BranchInstruction)i;
+                InstructionHandle itarget = bi.getTarget(); // old target
+
+                // New target must be in targetMap
+                InstructionHandle newTarget =
+                    (InstructionHandle)targetMap.get(itarget);
+
+                bc.setTarget(newTarget);
+
+                // Handle LOOKUPSWITCH or TABLESWITCH which may have many
+                // target instructions
+                if (bi instanceof Select) {
+                    InstructionHandle[] itargets = ((Select)bi).getTargets();
+                    InstructionHandle[] ctargets = ((Select)bc).getTargets();
+
+                    // Update all targets
+                    for (int j=0; j < itargets.length; j++) {
+                        ctargets[j] =
+                            (InstructionHandle)targetMap.get(itargets[j]);
+                    }
+                }
+            }  else if (i instanceof LocalVariableInstruction
+                            || i instanceof RET) {
+                // For any instruction that touches a local variable,
+                // map the location of the variable in the