8153082: Update XSLT compiler to generate classes that invoke addReads
Summary: This fix updates the XSLT compiler to generate Module.addReads statements for external function calls (see FunctionCall.java)
Reviewed-by: alanb, clanger, joehw
--- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/Constants.java Thu Jul 21 17:14:40 2016 +0000
+++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/Constants.java Tue Jul 26 14:29:54 2016 +0100
@@ -1,15 +1,15 @@
/*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
*/
/*
- * Copyright 2001-2004 The Apache Software Foundation.
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
*
- * 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
+ * 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,
@@ -98,6 +98,10 @@
public static final int ACC_STATIC
= com.sun.org.apache.bcel.internal.Constants.ACC_STATIC;
+ public static final String MODULE_SIG
+ = "Ljava/lang/reflect/Module;";
+ public static final String CLASS_SIG
+ = "Ljava/lang/Class;";
public static final String STRING_SIG
= "Ljava/lang/String;";
public static final String STRING_BUFFER_SIG
@@ -246,8 +250,12 @@
= "com.sun.org.apache.xalan.internal.xsltc.DOM";
public static final String DOM_IMPL
= "com.sun.org.apache.xalan.internal.xsltc.dom.SAXImpl";
- public static final String SAX_IMPL
+ public static final String SAX_IMPL
= "com.sun.org.apache.xalan.internal.xsltc.dom.SAXImpl";
+ public static final String CLASS_CLASS
+ = "java.lang.Class";
+ public static final String MODULE_CLASS
+ = "java.lang.reflect.Module";
public static final String STRING_CLASS
= "java.lang.String";
public static final String OBJECT_CLASS
@@ -293,7 +301,7 @@
= "()D";
public static final String DOM_PNAME
- = "dom";
+ = "dom";
public static final String NODE_PNAME
= "node";
public static final String TRANSLET_OUTPUT_PNAME
@@ -335,6 +343,19 @@
= "setStartNode";
public static final String RESET
= "reset";
+ public static final String GET_MODULE
+ = "getModule";
+ public static final String FOR_NAME
+ = "forName";
+ public static final String ADD_READS
+ = "addReads";
+
+ public static final String GET_MODULE_SIG
+ = "()" + MODULE_SIG;
+ public static final String FOR_NAME_SIG
+ = "(" + STRING_SIG + ")" + CLASS_SIG;
+ public static final String ADD_READS_SIG
+ = "(" + MODULE_SIG + ")" + MODULE_SIG;
public static final String ATTR_SET_SIG
= "(" + DOM_INTF_SIG + NODE_ITERATOR_SIG + TRANSLET_OUTPUT_SIG + "I)V";
--- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/FunctionCall.java Thu Jul 21 17:14:40 2016 +0000
+++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/FunctionCall.java Tue Jul 26 14:29:54 2016 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -17,9 +17,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-/*
- * $Id: FunctionCall.java,v 1.2.4.1 2005/09/12 10:31:32 pvedula Exp $
- */
package com.sun.org.apache.xalan.internal.xsltc.compiler;
@@ -32,6 +29,7 @@
import com.sun.org.apache.bcel.internal.generic.InstructionConstants;
import com.sun.org.apache.bcel.internal.generic.InstructionList;
import com.sun.org.apache.bcel.internal.generic.InvokeInstruction;
+import com.sun.org.apache.bcel.internal.generic.LDC;
import com.sun.org.apache.bcel.internal.generic.LocalVariableGen;
import com.sun.org.apache.bcel.internal.generic.NEW;
import com.sun.org.apache.bcel.internal.generic.PUSH;
@@ -792,6 +790,11 @@
final String clazz =
_chosenConstructor.getDeclaringClass().getName();
+
+ // Generate call to Module.addReads:
+ // <TransletClass>.class.getModule().addReads(
+ generateAddReads(classGen, methodGen, clazz);
+
Class[] paramTypes = _chosenConstructor.getParameterTypes();
LocalVariableGen[] paramTemp = new LocalVariableGen[n];
@@ -855,6 +858,12 @@
final String clazz = _chosenMethod.getDeclaringClass().getName();
Class[] paramTypes = _chosenMethod.getParameterTypes();
+
+ // Generate call to Module.addReads:
+ // <TransletClass>.class.getModule().addReads(
+ // Class.forName(<clazz>).getModule());
+ generateAddReads(classGen, methodGen, clazz);
+
// Push "this" if it is an instance method
if (_thisArgument != null) {
_thisArgument.translate(classGen, methodGen);
@@ -896,6 +905,41 @@
}
}
+ private void generateAddReads(ClassGenerator classGen, MethodGenerator methodGen,
+ String clazz) {
+ final ConstantPoolGen cpg = classGen.getConstantPool();
+ final InstructionList il = methodGen.getInstructionList();
+
+ // Generate call to Module.addReads:
+ // <TransletClass>.class.getModule().addReads(
+ // Class.forName(<clazz>).getModule());
+ // Class.forName may throw ClassNotFoundException.
+ // This is OK as it will caught higher up the stack in
+ // TransformerImpl.transform() and wrapped into a
+ // TransformerException.
+ methodGen.markChunkStart();
+
+ int index = cpg.addMethodref(CLASS_CLASS,
+ GET_MODULE,
+ GET_MODULE_SIG);
+ int index2 = cpg.addMethodref(CLASS_CLASS,
+ FOR_NAME,
+ FOR_NAME_SIG);
+ il.append(new LDC(cpg.addString(classGen.getClassName())));
+ il.append(new INVOKESTATIC(index2));
+ il.append(new INVOKEVIRTUAL(index));
+ il.append(new LDC(cpg.addString(clazz)));
+ il.append(new INVOKESTATIC(index2));
+ il.append(new INVOKEVIRTUAL(index));
+ index = cpg.addMethodref(MODULE_CLASS,
+ ADD_READS,
+ ADD_READS_SIG);
+ il.append(new INVOKEVIRTUAL(index));
+ il.append(InstructionConstants.POP);
+
+ methodGen.markChunkEnd();
+ }
+
@Override
public String toString() {
return "funcall(" + _fname + ", " + _arguments + ')';
--- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TemplatesImpl.java Thu Jul 21 17:14:40 2016 +0000
+++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/trax/TemplatesImpl.java Tue Jul 26 14:29:54 2016 +0100
@@ -58,7 +58,6 @@
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.URIResolver;
-import jdk.internal.module.Modules;
/**
* @author Morten Jorgensen
@@ -486,10 +485,6 @@
thisModule.addExports(p, m);
});
- // For now, the module reads all unnnamed modules. This will be changed once
- // the XSLT compiler is updated to generate code to invoke addReads.
- Modules.addReadsAllUnnamed(m);
-
// java.xml needs to instanitate the translet class
thisModule.addReads(m);
@@ -513,7 +508,7 @@
}
catch (ClassFormatError e) {
ErrorMsg err = new ErrorMsg(ErrorMsg.TRANSLET_CLASS_ERR, _name);
- throw new TransformerConfigurationException(err.toString());
+ throw new TransformerConfigurationException(err.toString(), e);
}
catch (LinkageError e) {
ErrorMsg err = new ErrorMsg(ErrorMsg.TRANSLET_OBJECT_ERR, _name);
--- a/jaxp/test/javax/xml/jaxp/unittest/transform/XSLTFunctionsTest.java Thu Jul 21 17:14:40 2016 +0000
+++ b/jaxp/test/javax/xml/jaxp/unittest/transform/XSLTFunctionsTest.java Tue Jul 26 14:29:54 2016 +0100
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -46,7 +46,7 @@
public class XSLTFunctionsTest {
/**
- * @bug 8062518
+ * @bug 8062518 8153082
* Verifies that a reference to the DTM created by XSLT document function is
* actually read from the DTM by an extension function.
* @param xml Content of xml file to process