< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java

Print this page
*** 161,10 ***
--- 161,13 ---
      public static final int FLAG_MARKERS = LambdaMetafactory.FLAG_MARKERS;
  
      /** Flag for alternate metafactories indicating the lambda object requires multiple bridges */
      public static final int FLAG_BRIDGES = LambdaMetafactory.FLAG_BRIDGES;
  
+     /** Flag for alternate metafactories indicating the lambda object is intended to be quotable */
+     public static final int FLAG_QUOTABLE = 1 << 3;
+ 
      // <editor-fold defaultstate="collapsed" desc="Instantiating">
      protected static final Context.Key<LambdaToMethod> unlambdaKey = new Context.Key<>();
  
      public static LambdaToMethod instance(Context context) {
          LambdaToMethod instance = context.get(unlambdaKey);

*** 826,12 ***
                  List.nil(),
                  syms.methodClass);
  
          List<Symbol> bridges = bridges(tree);
          boolean isSerializable = isSerializable(tree);
          boolean needsAltMetafactory = tree.target.isIntersection() ||
!                 isSerializable || bridges.length() > 1;
  
          dumpStats(tree, needsAltMetafactory, nonDedupedRefSym);
  
          Name metafactoryName = needsAltMetafactory ?
                  names.altMetafactory : names.metafactory;
--- 829,13 ---
                  List.nil(),
                  syms.methodClass);
  
          List<Symbol> bridges = bridges(tree);
          boolean isSerializable = isSerializable(tree);
+         boolean isQuotable = isQuotable(tree);
          boolean needsAltMetafactory = tree.target.isIntersection() ||
!                 isSerializable || isQuotable || bridges.length() > 1;
  
          dumpStats(tree, needsAltMetafactory, nonDedupedRefSym);
  
          Name metafactoryName = needsAltMetafactory ?
                  names.altMetafactory : names.metafactory;

*** 842,16 ***
--- 846,18 ---
                      types.directSupertypes(tree.target) :
                      List.nil();
              for (Type t : targets) {
                  t = types.erasure(t);
                  if (t.tsym != syms.serializableType.tsym &&
+                         !types.isQuotable(t) &&
                          t.tsym != tree.type.tsym &&
                          t.tsym != syms.objectType.tsym) {
                      markers.append(t);
                  }
              }
              int flags = isSerializable ? FLAG_SERIALIZABLE : 0;
+             flags |= isQuotable ? FLAG_QUOTABLE : 0;
              boolean hasMarkers = markers.nonEmpty();
              boolean hasBridges = bridges.nonEmpty();
              if (hasMarkers) {
                  flags |= FLAG_MARKERS;
              }

*** 870,10 ***
--- 876,14 ---
                      if (!types.isSameType(s_erasure, samSym.erasure(types))) {
                          staticArgs = staticArgs.append(((MethodType)s.erasure(types)));
                      }
                  }
              }
+             if (isQuotable) {
+                 VarSymbol reflectField = (VarSymbol)tree.codeModel;
+                 staticArgs = staticArgs.append(reflectField.asMethodHandle(true));
+             }
              if (isSerializable) {
                  int prevPos = make.pos;
                  try {
                      make.at(kInfo.clazz);
                      addDeserializationCase(refSym, tree.type, samSym,

*** 936,10 ***
--- 946,14 ---
              return true;
          }
          return types.asSuper(tree.target, syms.serializableType.tsym) != null;
      }
  
+     boolean isQuotable(JCFunctionalExpression tree) {
+         return tree.codeModel != null;
+     }
+ 
      void dumpStats(JCFunctionalExpression tree, boolean needsAltMetafactory, Symbol sym) {
          if (dumpLambdaToMethodStats) {
              if (tree instanceof JCLambda lambda) {
                  log.note(tree, diags.noteKey(lambda.wasMethodReference ? "mref.stat.1" : "lambda.stat",
                          needsAltMetafactory, sym));
< prev index next >