NPE in isSignaturePolymorphic(jdk.compiler at 9-internal/Types.java:1079)

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Tue Oct 25 20:29:16 UTC 2016


Thanks for the headsup (and the patch). This is an oversight in our 
implementation.

Maurizio


On 25/10/16 21:02, Ronald Servant wrote:
>
> Hi,
>
> When compiling the IBM J9 JVM classes for method handles, we hit an 
> internal compiler bug.
>
> java.lang.NullPointerException
>
>  at com.sun.tools.javac.code.Types.isSignaturePolymorphic(Types.java:1005)
>
>  at 
> com.sun.tools.javac.comp.MemberEnter.visitMethodDef(MemberEnter.java:199)
>
>  at com.sun.tools.javac.tree.JCTree$JCMethodDecl.accept(JCTree.java:852)
>
>  at com.sun.tools.javac.comp.MemberEnter.memberEnter(MemberEnter.java:161)
>
>  at com.sun.tools.javac.comp.MemberEnter.memberEnter(MemberEnter.java:173)
>
>  at 
> com.sun.tools.javac.comp.TypeEnter$MembersPhase.finishClass(TypeEnter.java:968)
>
>  at 
> com.sun.tools.javac.comp.TypeEnter$MembersPhase.runPhase(TypeEnter.java:953)
>
>  at 
> com.sun.tools.javac.comp.TypeEnter$Phase.doCompleteEnvs(TypeEnter.java:272)
>
>  at 
> com.sun.tools.javac.comp.TypeEnter$MembersPhase.doCompleteEnvs(TypeEnter.java:888)
>
>  at 
> com.sun.tools.javac.comp.TypeEnter$Phase.completeEnvs(TypeEnter.java:247)
>
> The check performed in isSignaturePolymorphic() assumes that all 
> native methods in MethodHandle or VarHandle will have at least 1 
> parameter.  That true for OpenJDK, but in the J9 implementation, we 
> have native methods without parameters.  This issue can be reproduced 
> by applying patch[1] below.
>
> Patch[2], below, adds a null check before 'argtypes.tail.tail == 
> null', as the NPE occurs when the second tail variable is dereferenced.
>
> When a native method with no parameters is added to MethodHandle or 
> VarHandle, 'argtypes.tail' is null.   It might also be prudent to add 
> a null check to argtypesbefore dereferencing argtypes.tail.
>
> Patch[1]:
>
> To reproduce apply this patch to the jdk repository, and run make all 
> (or make java.base):
>
> diff -r 11e15af1947f 
> src/java.base/share/classes/java/lang/invoke/MethodHandle.java
>
> --- a/src/java.base/share/classes/java/lang/invoke/MethodHandle.java   
>  Tue Oct 25 07:38:50 2016 -0700
>
> +++ b/src/java.base/share/classes/java/lang/invoke/MethodHandle.java   
>  Tue Oct 25 15:54:56 2016 -0400
>
> @@ -483,6 +483,12 @@
>
>     */
>
>    @HotSpotIntrinsicCandidate
>
>    public final native @PolymorphicSignature Object 
> invokeExact(Object... args) throws Throwable;
>
> +
>
> +    /**
>
> +     * this is a test method to reproduce a bug in javac
>
> +     * @return nothing of interest
>
> +     */
>
> +    public static native Object test();
>
>    /**
>
>     * Invokes the method handle, allowing any caller type descriptor,
>
> @@ -1594,4 +1600,5 @@
>
>            throw newInternalError(ex);
>
>        }
>
>    }
>
> +
>
>  }
>
> Patch[2]:
>
> To fix, apply this patch:
>
> diff -r 32444e1ad88a 
> src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java
>
> --- 
> a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java 
>  Tue Oct 25 08:39:12 2016 -0700
>
> +++ 
> b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java 
>  Tue Oct 25 15:57:05 2016 -0400
>
> @@ -1004,6 +1004,7 @@
>
>       List<Type> argtypes = msym.type.getParameterTypes();
>
>       return (msym.flags_field & NATIVE) != 0 &&
>
>             (msym.owner == syms.methodHandleType.tsym || msym.owner == 
> syms.varHandleType.tsym) &&
>
> +               argtypes.tail != null &&
>
>               argtypes.tail.tail == null &&
>
>               argtypes.head.hasTag(TypeTag.ARRAY) &&
>
>               ((ArrayType)argtypes.head).elemtype.tsym == 
> syms.objectType.tsym;
>
> Thank you,
> Ronald Servant
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20161025/eb9ecbf9/attachment-0001.html>


More information about the compiler-dev mailing list