提交 bd2bcf9e 编写于 作者: V vromero

8016569: javac, add new flag for polymorphic method signatures

Reviewed-by: jjg
Contributed-by: maurizio.cimadamore@oracle.com
上级 0c56bf05
...@@ -278,6 +278,11 @@ public class Flags { ...@@ -278,6 +278,11 @@ public class Flags {
*/ */
public static final long BAD_OVERRIDE = 1L<<45; public static final long BAD_OVERRIDE = 1L<<45;
/**
* Flag that indicates a signature polymorphic method (292).
*/
public static final long SIGNATURE_POLYMORPHIC = 1L<<46;
/** Modifier masks. /** Modifier masks.
*/ */
public static final int public static final int
......
...@@ -1537,25 +1537,6 @@ public abstract class Symbol implements Element { ...@@ -1537,25 +1537,6 @@ public abstract class Symbol implements Element {
getKind() == ElementKind.INSTANCE_INIT; getKind() == ElementKind.INSTANCE_INIT;
} }
/**
* A polymorphic signature method (JLS SE 7, 8.4.1) 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.
*/
public boolean isSignaturePolymorphic(Types types) {
List<Type> argtypes = type.getParameterTypes();
Type firstElemType = argtypes.nonEmpty() ?
types.elemtype(argtypes.head) :
null;
return owner == types.syms.methodHandleType.tsym &&
argtypes.length() == 1 &&
firstElemType != null &&
types.isSameType(firstElemType, types.syms.objectType) &&
types.isSameType(type.getReturnType(), types.syms.objectType) &&
(flags() & NATIVE) != 0;
}
public Attribute getDefaultValue() { public Attribute getDefaultValue() {
return defaultValue; return defaultValue;
} }
......
...@@ -950,6 +950,22 @@ public class Types { ...@@ -950,6 +950,22 @@ public class Types {
/*inlined: ts.isEmpty() && ss.isEmpty();*/ /*inlined: ts.isEmpty() && ss.isEmpty();*/
} }
/**
* A polymorphic signature method (JLS SE 7, 8.4.1) 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.
*/
public boolean isSignaturePolymorphic(MethodSymbol msym) {
List<Type> argtypes = msym.type.getParameterTypes();
return (msym.flags_field & NATIVE) != 0 &&
msym.owner == syms.methodHandleType.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;
}
/** /**
* Is t the same type as s? * Is t the same type as s?
*/ */
......
...@@ -3405,7 +3405,7 @@ public class Attr extends JCTree.Visitor { ...@@ -3405,7 +3405,7 @@ public class Attr extends JCTree.Visitor {
Env<AttrContext> env, Env<AttrContext> env,
ResultInfo resultInfo) { ResultInfo resultInfo) {
boolean isPolymorhicSignature = boolean isPolymorhicSignature =
sym.kind == MTH && ((MethodSymbol)sym.baseSymbol()).isSignaturePolymorphic(types); (sym.baseSymbol().flags() & SIGNATURE_POLYMORPHIC) != 0;
return isPolymorhicSignature ? return isPolymorhicSignature ?
checkSigPolyMethodId(tree, site, sym, env, resultInfo) : checkSigPolyMethodId(tree, site, sym, env, resultInfo) :
checkMethodIdInternal(tree, site, sym, env, resultInfo); checkMethodIdInternal(tree, site, sym, env, resultInfo);
......
...@@ -909,7 +909,7 @@ public class Check { ...@@ -909,7 +909,7 @@ public class Check {
"unchecked.generic.array.creation", "unchecked.generic.array.creation",
argtype); argtype);
} }
if (!((MethodSymbol)sym.baseSymbol()).isSignaturePolymorphic(types)) { if ((sym.baseSymbol().flags() & SIGNATURE_POLYMORPHIC) == 0) {
TreeInfo.setVarargsElement(env.tree, types.elemtype(argtype)); TreeInfo.setVarargsElement(env.tree, types.elemtype(argtype));
} }
} }
......
...@@ -560,6 +560,10 @@ public class MemberEnter extends JCTree.Visitor implements Completer { ...@@ -560,6 +560,10 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
chk.setDeferredLintHandler(prevLintHandler); chk.setDeferredLintHandler(prevLintHandler);
} }
if (types.isSignaturePolymorphic(m)) {
m.flags_field |= SIGNATURE_POLYMORPHIC;
}
// Set m.params // Set m.params
ListBuffer<VarSymbol> params = new ListBuffer<VarSymbol>(); ListBuffer<VarSymbol> params = new ListBuffer<VarSymbol>();
JCVariableDecl lastParam = null; JCVariableDecl lastParam = null;
......
...@@ -2267,7 +2267,7 @@ public class Resolve { ...@@ -2267,7 +2267,7 @@ public class Resolve {
sym = super.access(env, pos, location, sym); sym = super.access(env, pos, location, sym);
} else if (allowMethodHandles) { } else if (allowMethodHandles) {
MethodSymbol msym = (MethodSymbol)sym; MethodSymbol msym = (MethodSymbol)sym;
if (msym.isSignaturePolymorphic(types)) { if ((msym.flags() & SIGNATURE_POLYMORPHIC) != 0) {
return findPolymorphicSignatureInstance(env, sym, argtypes); return findPolymorphicSignatureInstance(env, sym, argtypes);
} }
} }
......
...@@ -1985,6 +1985,9 @@ public class ClassReader implements Completer { ...@@ -1985,6 +1985,9 @@ public class ClassReader implements Completer {
syms.methodClass); syms.methodClass);
} }
MethodSymbol m = new MethodSymbol(flags, name, type, currentOwner); MethodSymbol m = new MethodSymbol(flags, name, type, currentOwner);
if (types.isSignaturePolymorphic(m)) {
m.flags_field |= SIGNATURE_POLYMORPHIC;
}
if (saveParameterNames) if (saveParameterNames)
initParameterNames(m); initParameterNames(m);
Symbol prevOwner = currentOwner; Symbol prevOwner = currentOwner;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册