Merge
authoramurillo
Tue, 05 Apr 2016 20:02:21 -0700
changeset 37000 3ce4dee5a400
parent 36994 b6fede3120ae (current diff)
parent 36999 4bf32dc5215d (diff)
child 37001 594b4565d8a4
Merge
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symtab.java	Tue Apr 05 21:17:25 2016 +0100
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symtab.java	Tue Apr 05 20:02:21 2016 -0700
@@ -167,6 +167,7 @@
     public final Type cloneableType;
     public final Type serializableType;
     public final Type serializedLambdaType;
+    public final Type varHandleType;
     public final Type methodHandleType;
     public final Type methodHandleLookupType;
     public final Type methodTypeType;
@@ -468,6 +469,7 @@
         throwableType = enterClass("java.lang.Throwable");
         serializableType = enterClass("java.io.Serializable");
         serializedLambdaType = enterClass("java.lang.invoke.SerializedLambda");
+        varHandleType = enterClass("java.lang.invoke.VarHandle");
         methodHandleType = enterClass("java.lang.invoke.MethodHandle");
         methodHandleLookupType = enterClass("java.lang.invoke.MethodHandles$Lookup");
         methodTypeType = enterClass("java.lang.invoke.MethodType");
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java	Tue Apr 05 21:17:25 2016 +0100
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java	Tue Apr 05 20:02:21 2016 -0700
@@ -1062,18 +1062,19 @@
     }
 
     /**
-    * A polymorphic signature method (JLS 15.12.3) is a method that
-    * (i) is declared in the java.lang.invoke.MethodHandle class, (ii) takes
-    * a single variable arity parameter (iii) whose declared type is Object[],
-    * (iv) has a return type of Object and (v) is native.
+     * A polymorphic signature method (JLS 15.12.3) is a method that
+     *   (i) is declared in the java.lang.invoke.MethodHandle/VarHandle classes;
+     *  (ii) takes a single variable arity parameter;
+     * (iii) whose declared type is Object[];
+     *  (iv) has any return type, Object signifying a polymorphic return type; and
+     *   (v) is native.
     */
    public boolean isSignaturePolymorphic(MethodSymbol msym) {
        List<Type> argtypes = msym.type.getParameterTypes();
        return (msym.flags_field & NATIVE) != 0 &&
-               msym.owner == syms.methodHandleType.tsym &&
+              (msym.owner == syms.methodHandleType.tsym || msym.owner == syms.varHandleType.tsym) &&
                argtypes.tail.tail == null &&
                argtypes.head.hasTag(TypeTag.ARRAY) &&
-               msym.type.getReturnType().tsym == syms.objectType.tsym &&
                ((ArrayType)argtypes.head).elemtype.tsym == syms.objectType.tsym;
    }
 
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Infer.java	Tue Apr 05 21:17:25 2016 +0100
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Infer.java	Tue Apr 05 20:02:21 2016 -0700
@@ -560,30 +560,37 @@
                                             List<Type> argtypes) {
         final Type restype;
 
-        //The return type for a polymorphic signature call is computed from
-        //the enclosing tree E, as follows: if E is a cast, then use the
-        //target type of the cast expression as a return type; if E is an
-        //expression statement, the return type is 'void' - otherwise the
-        //return type is simply 'Object'. A correctness check ensures that
-        //env.next refers to the lexically enclosing environment in which
-        //the polymorphic signature call environment is nested.
+        if (spMethod == null || types.isSameType(spMethod.getReturnType(), syms.objectType, true)) {
+            // The return type of the polymorphic signature is polymorphic,
+            // and is computed from the enclosing tree E, as follows:
+            // if E is a cast, then use the target type of the cast expression
+            // as a return type; if E is an expression statement, the return
+            // type is 'void'; otherwise
+            // the return type is simply 'Object'. A correctness check ensures
+            // that env.next refers to the lexically enclosing environment in
+            // which the polymorphic signature call environment is nested.
 
-        switch (env.next.tree.getTag()) {
-            case TYPECAST:
-                JCTypeCast castTree = (JCTypeCast)env.next.tree;
-                restype = (TreeInfo.skipParens(castTree.expr) == env.tree) ?
-                    castTree.clazz.type :
-                    syms.objectType;
-                break;
-            case EXEC:
-                JCTree.JCExpressionStatement execTree =
-                        (JCTree.JCExpressionStatement)env.next.tree;
-                restype = (TreeInfo.skipParens(execTree.expr) == env.tree) ?
-                    syms.voidType :
-                    syms.objectType;
-                break;
-            default:
-                restype = syms.objectType;
+            switch (env.next.tree.getTag()) {
+                case TYPECAST:
+                    JCTypeCast castTree = (JCTypeCast)env.next.tree;
+                    restype = (TreeInfo.skipParens(castTree.expr) == env.tree) ?
+                              castTree.clazz.type :
+                              syms.objectType;
+                    break;
+                case EXEC:
+                    JCTree.JCExpressionStatement execTree =
+                            (JCTree.JCExpressionStatement)env.next.tree;
+                    restype = (TreeInfo.skipParens(execTree.expr) == env.tree) ?
+                              syms.voidType :
+                              syms.objectType;
+                    break;
+                default:
+                    restype = syms.objectType;
+            }
+        } else {
+            // The return type of the polymorphic signature is fixed
+            // (not polymorphic)
+            restype = spMethod.getReturnType();
         }
 
         List<Type> paramtypes = argtypes.map(new ImplicitArgType(spMethod, resolveContext.step));
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java	Tue Apr 05 21:17:25 2016 +0100
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java	Tue Apr 05 20:02:21 2016 -0700
@@ -2492,13 +2492,19 @@
         Type mtype = infer.instantiatePolymorphicSignatureInstance(env,
                 (MethodSymbol)spMethod, currentResolutionContext, argtypes);
         for (Symbol sym : polymorphicSignatureScope.getSymbolsByName(spMethod.name)) {
-            if (types.isSameType(mtype, sym.type)) {
-               return sym;
+            // Check that there is already a method symbol for the method
+            // type and owner
+            if (types.isSameType(mtype, sym.type) &&
+                spMethod.owner == sym.owner) {
+                return sym;
             }
         }
 
-        // create the desired method
-        long flags = ABSTRACT | HYPOTHETICAL | spMethod.flags() & Flags.AccessFlags;
+        // Create the desired method
+        // Retain static modifier is to support invocations to
+        // MethodHandle.linkTo* methods
+        long flags = ABSTRACT | HYPOTHETICAL |
+                     spMethod.flags() & (Flags.AccessFlags | Flags.STATIC);
         Symbol msym = new MethodSymbol(flags, spMethod.name, mtype, spMethod.owner) {
             @Override
             public Symbol baseSymbol() {