--- old/jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/FunctionCall.java 2016-07-22 17:09:07.000000000 +0100 +++ new/jaxp/src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/FunctionCall.java 2016-07-22 17:09:07.000000000 +0100 @@ -32,8 +32,10 @@ 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.POP; import com.sun.org.apache.bcel.internal.generic.PUSH; import com.sun.org.apache.xalan.internal.utils.FeatureManager; import com.sun.org.apache.xalan.internal.utils.ObjectFactory; @@ -792,6 +794,11 @@ final String clazz = _chosenConstructor.getDeclaringClass().getName(); + + // Generate call to Module.addReads: + // .class.getModule().addReads( + generateAddReads(classGen, methodGen, clazz); + Class[] paramTypes = _chosenConstructor.getParameterTypes(); LocalVariableGen[] paramTemp = new LocalVariableGen[n]; @@ -855,6 +862,12 @@ final String clazz = _chosenMethod.getDeclaringClass().getName(); Class[] paramTypes = _chosenMethod.getParameterTypes(); + + // Generate call to Module.addReads: + // .class.getModule().addReads( + // Class.forName().getModule()); + generateAddReads(classGen, methodGen, clazz); + // Push "this" if it is an instance method if (_thisArgument != null) { _thisArgument.translate(classGen, methodGen); @@ -896,6 +909,47 @@ } } + private void generateAddReads(ClassGenerator classGen, MethodGenerator methodGen, + String clazz) { + final ConstantPoolGen cpg = classGen.getConstantPool(); + final InstructionList il = methodGen.getInstructionList(); + + if (classGen.getMajor() < com.sun.org.apache.bcel.internal.Constants.MAJOR_1_5) { + // Major version needs to be >= 5.0 in order to support loading + // a class ref from the constant pool (LDC) + classGen.setMajor(com.sun.org.apache.bcel.internal.Constants.MAJOR_1_5); + classGen.setMinor(com.sun.org.apache.bcel.internal.Constants.MINOR_1_5); + } + + // Generate call to Module.addReads: + // .class.getModule().addReads( + // Class.forName().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); + il.append(new LDC(cpg.addClass(classGen.getClassName()))); + il.append(new INVOKEVIRTUAL(index)); + int index2 = cpg.addMethodref(CLASS_CLASS, + FOR_NAME, + FOR_NAME_SIG); + 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(new POP()); + + methodGen.markChunkEnd(); + } + @Override public String toString() { return "funcall(" + _fname + ", " + _arguments + ')';