< prev index next >
src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java
Print this page
@@ -34,11 +34,10 @@
import com.sun.tools.javac.tree.JCTree.*;
import com.sun.tools.javac.tree.JCTree.JCMemberReference.ReferenceKind;
import com.sun.tools.javac.tree.TreeMaker;
import com.sun.tools.javac.tree.TreeTranslator;
import com.sun.tools.javac.code.Attribute;
-import com.sun.tools.javac.code.Scope.WriteableScope;
import com.sun.tools.javac.code.Symbol;
import com.sun.tools.javac.code.Symbol.ClassSymbol;
import com.sun.tools.javac.code.Symbol.DynamicMethodSymbol;
import com.sun.tools.javac.code.Symbol.MethodSymbol;
import com.sun.tools.javac.code.Symbol.TypeSymbol;
@@ -125,10 +124,13 @@
private final boolean verboseDeduplication;
/** deduplicate lambda implementation methods */
private final boolean deduplicateLambdas;
+ /** lambda proxy is a dynamic nestmate */
+ private final boolean nestmateLambdas;
+
/** Flag for alternate metafactories indicating the lambda object is intended to be serializable */
public static final int FLAG_SERIALIZABLE = 1 << 0;
/** Flag for alternate metafactories indicating the lambda object has multiple targets */
public static final int FLAG_MARKERS = 1 << 1;
@@ -166,10 +168,11 @@
debugLinesOrVars = options.isSet(Option.G)
|| options.isSet(Option.G_CUSTOM, "lines")
|| options.isSet(Option.G_CUSTOM, "vars");
verboseDeduplication = options.isSet("debug.dumpLambdaToMethodDeduplication");
deduplicateLambdas = options.getBoolean("deduplicateLambdas", true);
+ nestmateLambdas = Target.instance(context).runtimeUseNestAccess();
}
// </editor-fold>
class DedupedLambda {
private final MethodSymbol symbol;
@@ -2251,10 +2254,24 @@
//when 292 issue is fixed we should remove this and change the backend
//code to always generate a method handle to an accessible method
return tree.ownerAccessible;
}
+ /**
+ * This method should be called only when target release <= 14
+ * where LambdaMetaFactory does not spin nestmate classes.
+ *
+ * This method should be removed when --release 14 is not supported.
+ */
+ boolean isPrivateInOtherClass() {
+ assert !nestmateLambdas;
+ return (tree.sym.flags() & PRIVATE) != 0 &&
+ !types.isSameType(
+ types.erasure(tree.sym.enclClass().asType()),
+ types.erasure(owner.enclClass().asType()));
+ }
+
boolean isProtectedInSuperClassOfEnclosingClassInOtherPackage() {
return ((tree.sym.flags() & PROTECTED) != 0 &&
tree.sym.packge() != owner.packge());
}
@@ -2291,10 +2308,11 @@
final boolean needsConversionToLambda() {
return interfaceParameterIsIntersectionOrUnionType() ||
isSuper ||
needsVarArgsConversion() ||
isArrayOp() ||
+ (!nestmateLambdas && isPrivateInOtherClass()) ||
isProtectedInSuperClassOfEnclosingClassInOtherPackage() ||
!receiverAccessible() ||
(tree.getMode() == ReferenceMode.NEW &&
tree.kind != ReferenceKind.ARRAY_CTOR &&
(tree.sym.owner.isLocal() || tree.sym.owner.isInner()));
< prev index next >