changeset 2826:43acad66372b

Merge
author asaha
date Thu, 09 Apr 2015 22:59:11 -0700
parents 6561609f52ab c18117bf5a9f
children ac218cf56d8b
files .hgtags
diffstat 15 files changed, 264 insertions(+), 56 deletions(-) [+]
line wrap: on
line diff
--- a/.hgtags	Wed Apr 01 11:34:59 2015 -0700
+++ b/.hgtags	Thu Apr 09 22:59:11 2015 -0700
@@ -404,3 +404,4 @@
 39b47ffeb7780407561c0b189c3b3ab497868518 jdk8u60-b07
 e5b93c508212e0db2301cc25f5ada882367d1d9b jdk8u60-b08
 76adee5ad278e33675fdd236179fa83f20de5cc3 jdk8u60-b09
+ba758e1ffa6960266e5c619b7771ca779ee5d148 jdk8u60-b10
--- a/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java	Wed Apr 01 11:34:59 2015 -0700
+++ b/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java	Thu Apr 09 22:59:11 2015 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -224,7 +224,8 @@
             DeferredStuckPolicy deferredStuckPolicy;
             if (resultInfo.pt.hasTag(NONE) || resultInfo.pt.isErroneous()) {
                 deferredStuckPolicy = dummyStuckPolicy;
-            } else if (resultInfo.checkContext.deferredAttrContext().mode == AttrMode.SPECULATIVE) {
+            } else if (resultInfo.checkContext.deferredAttrContext().mode == AttrMode.SPECULATIVE ||
+                    resultInfo.checkContext.deferredAttrContext().insideOverloadPhase()) {
                 deferredStuckPolicy = new OverloadStuckPolicy(resultInfo, this);
             } else {
                 deferredStuckPolicy = new CheckStuckPolicy(resultInfo, this);
--- a/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java	Wed Apr 01 11:34:59 2015 -0700
+++ b/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java	Thu Apr 09 22:59:11 2015 -0700
@@ -265,7 +265,7 @@
     @Override
     public void visitLambda(JCLambda tree) {
         LambdaTranslationContext localContext = (LambdaTranslationContext)context;
-        MethodSymbol sym = (MethodSymbol)localContext.translatedSym;
+        MethodSymbol sym = localContext.translatedSym;
         MethodType lambdaType = (MethodType) sym.type;
 
         {
@@ -1755,7 +1755,7 @@
             Map<LambdaSymbolKind, Map<Symbol, Symbol>> translatedSymbols;
 
             /** the synthetic symbol for the method hoisting the translated lambda */
-            Symbol translatedSym;
+            MethodSymbol translatedSym;
 
             List<JCVariableDecl> syntheticParams;
 
@@ -1883,7 +1883,7 @@
              * Translate a symbol of a given kind into something suitable for the
              * synthetic lambda body
              */
-            Symbol translate(Name name, final Symbol sym, LambdaSymbolKind skind) {
+            Symbol translate(final Symbol sym, LambdaSymbolKind skind) {
                 Symbol ret;
                 switch (skind) {
                     case CAPTURED_THIS:
@@ -1891,7 +1891,7 @@
                         break;
                     case TYPE_VAR:
                         // Just erase the type var
-                        ret = new VarSymbol(sym.flags(), name,
+                        ret = new VarSymbol(sym.flags(), sym.name,
                                 types.erasure(sym.type), sym.owner);
 
                         /* this information should also be kept for LVT generation at Gen
@@ -1900,7 +1900,7 @@
                         ((VarSymbol)ret).pos = ((VarSymbol)sym).pos;
                         break;
                     case CAPTURED_VAR:
-                        ret = new VarSymbol(SYNTHETIC | FINAL | PARAMETER, name, types.erasure(sym.type), translatedSym) {
+                        ret = new VarSymbol(SYNTHETIC | FINAL | PARAMETER, sym.name, types.erasure(sym.type), translatedSym) {
                             @Override
                             public Symbol baseSymbol() {
                                 //keep mapping with original captured symbol
@@ -1909,16 +1909,16 @@
                         };
                         break;
                     case LOCAL_VAR:
-                        ret = new VarSymbol(sym.flags() & FINAL, name, sym.type, translatedSym);
+                        ret = new VarSymbol(sym.flags() & FINAL, sym.name, sym.type, translatedSym);
                         ((VarSymbol) ret).pos = ((VarSymbol) sym).pos;
                         break;
                     case PARAM:
-                        ret = new VarSymbol((sym.flags() & FINAL) | PARAMETER, name, types.erasure(sym.type), translatedSym);
+                        ret = new VarSymbol((sym.flags() & FINAL) | PARAMETER, sym.name, types.erasure(sym.type), translatedSym);
                         ((VarSymbol) ret).pos = ((VarSymbol) sym).pos;
                         break;
                     default:
-                        ret = makeSyntheticVar(FINAL, name, types.erasure(sym.type), translatedSym);
-                        ((VarSymbol) ret).pos = ((VarSymbol) sym).pos;
+                        Assert.error(skind.name());
+                        throw new AssertionError();
                 }
                 if (ret != sym) {
                     ret.setDeclarationAttributes(sym.getRawAttributes());
@@ -1929,27 +1929,8 @@
 
             void addSymbol(Symbol sym, LambdaSymbolKind skind) {
                 Map<Symbol, Symbol> transMap = getSymbolMap(skind);
-                Name preferredName;
-                switch (skind) {
-                    case CAPTURED_THIS:
-                        preferredName = names.fromString("encl$" + transMap.size());
-                        break;
-                    case CAPTURED_VAR:
-                        preferredName = names.fromString("cap$" + transMap.size());
-                        break;
-                    case LOCAL_VAR:
-                        preferredName = sym.name;
-                        break;
-                    case PARAM:
-                        preferredName = sym.name;
-                        break;
-                    case TYPE_VAR:
-                        preferredName = sym.name;
-                        break;
-                    default: throw new AssertionError();
-                }
                 if (!transMap.containsKey(sym)) {
-                    transMap.put(sym, translate(preferredName, sym, skind));
+                    transMap.put(sym, translate(sym, skind));
                 }
             }
 
@@ -1997,6 +1978,7 @@
 
                 //compute synthetic params
                 ListBuffer<JCVariableDecl> params = new ListBuffer<>();
+                ListBuffer<VarSymbol> parameterSymbols = new ListBuffer<>();
 
                 // The signature of the method is augmented with the following
                 // synthetic parameters:
@@ -2005,19 +1987,16 @@
                 // 2) enclosing locals captured by the lambda expression
                 for (Symbol thisSym : getSymbolMap(CAPTURED_VAR).values()) {
                     params.append(make.VarDef((VarSymbol) thisSym, null));
-                }
-                if (methodReferenceReceiver != null) {
-                    params.append(make.VarDef(
-                            make.Modifiers(PARAMETER|FINAL),
-                            names.fromString("$rcvr$"),
-                            make.Type(methodReferenceReceiver.type),
-                            null));
+                    parameterSymbols.append((VarSymbol) thisSym);
                 }
                 for (Symbol thisSym : getSymbolMap(PARAM).values()) {
                     params.append(make.VarDef((VarSymbol) thisSym, null));
+                    parameterSymbols.append((VarSymbol) thisSym);
                 }
                 syntheticParams = params.toList();
 
+                translatedSym.params = parameterSymbols.toList();
+
                 // Compute and set the lambda name
                 translatedSym.name = isSerializable()
                         ? serializedLambdaName()
--- a/src/share/classes/com/sun/tools/javac/jvm/Code.java	Wed Apr 01 11:34:59 2015 -0700
+++ b/src/share/classes/com/sun/tools/javac/jvm/Code.java	Thu Apr 09 22:59:11 2015 -0700
@@ -2172,7 +2172,11 @@
         boolean keepLocalVariables = varDebugInfo ||
             (var.sym.isExceptionParameter() && var.sym.hasTypeAnnotations());
         if (!keepLocalVariables) return;
-        if ((var.sym.flags() & Flags.SYNTHETIC) != 0) return;
+        //don't keep synthetic vars, unless they are lambda method parameters
+        boolean ignoredSyntheticVar = (var.sym.flags() & Flags.SYNTHETIC) != 0 &&
+                ((var.sym.owner.flags() & Flags.LAMBDA_METHOD) == 0 ||
+                 (var.sym.flags() & Flags.PARAMETER) == 0);
+        if (ignoredSyntheticVar) return;
         if (varBuffer == null)
             varBuffer = new LocalVar[20];
         else
--- a/test/tools/javac/MethodParameters/ClassFileVisitor.java	Wed Apr 01 11:34:59 2015 -0700
+++ b/test/tools/javac/MethodParameters/ClassFileVisitor.java	Thu Apr 09 22:59:11 2015 -0700
@@ -147,6 +147,7 @@
         public int mAttrs;
         public int mNumParams;
         public boolean mSynthetic;
+        public boolean mIsLambda;
         public boolean mIsConstructor;
         public boolean mIsClinit;
         public boolean mIsBridge;
@@ -165,6 +166,7 @@
             mIsClinit = mName.equals("<clinit>");
             prefix = cname + "." + mName + "() - ";
             mIsBridge = method.access_flags.is(AccessFlags.ACC_BRIDGE);
+            mIsLambda = mSynthetic && mName.startsWith("lambda$");
 
             if (mIsClinit) {
                 sb = new StringBuilder(); // Discard output
@@ -225,7 +227,7 @@
 
             // IMPL: Whether MethodParameters attributes will be generated
             // for some synthetics is unresolved. For now, assume no.
-            if (mSynthetic) {
+            if (mSynthetic && !mIsLambda) {
                 warn(prefix + "synthetic has MethodParameter attribute");
             }
 
@@ -349,10 +351,12 @@
             } else if (isEnum && mNumParams == 1 && index == 0 && mName.equals("valueOf")) {
                 expect = "name";
                 allowMandated = true;
-            } else if (mIsBridge) {
+            } else if (mIsBridge || mIsLambda) {
                 allowSynthetic = true;
                 /*  you can't expect an special name for bridges' parameters.
-                 *  The name of the original parameters are now copied.
+                 *  The name of the original parameters are now copied. Likewise
+                 *  for a method encoding the lambda expression, names are derived
+                 *  from source lambda's parameters and captured enclosing locals.
                  */
                 expect = null;
             }
--- a/test/tools/javac/MethodParameters/LambdaTest.java	Wed Apr 01 11:34:59 2015 -0700
+++ b/test/tools/javac/MethodParameters/LambdaTest.java	Thu Apr 09 22:59:11 2015 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2015 Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 8006582
+ * @bug 8006582 8037546
  * @summary javac should generate method parameters correctly.
  * @build Tester
  * @compile -parameters LambdaTest.java
@@ -31,8 +31,8 @@
  */
 
 /**
- * Parameter names are not recorded for lambdas. This test verifies
- * that there are no MethodParameters attribute for lambdas.
+ * Post https://bugs.openjdk.java.net/browse/JDK-8037546, this test verifies
+ * that MethodParameters attribute for lambdas are emitted properly.
  */
 class LambdaTest {
 
--- a/test/tools/javac/MethodParameters/LambdaTest.out	Wed Apr 01 11:34:59 2015 -0700
+++ b/test/tools/javac/MethodParameters/LambdaTest.out	Thu Apr 09 22:59:11 2015 -0700
@@ -1,7 +1,7 @@
 class LambdaTest -- 
 LambdaTest.<init>()
 LambdaTest.foo(i)
-LambdaTest.lambda$static$1(arg0)/*synthetic*/
-LambdaTest.lambda$null$0(arg0, arg1)/*synthetic*/
+LambdaTest.lambda$static$1(x1/*synthetic*/)/*synthetic*/
+LambdaTest.lambda$null$0(final x1/*synthetic*/, x2/*synthetic*/)/*synthetic*/
 static interface LambdaTest$I -- inner
 LambdaTest$I.m(x)
--- a/test/tools/javac/MethodParameters/ReflectionVisitor.java	Wed Apr 01 11:34:59 2015 -0700
+++ b/test/tools/javac/MethodParameters/ReflectionVisitor.java	Thu Apr 09 22:59:11 2015 -0700
@@ -277,7 +277,7 @@
                     param = "final " + param;
                 }
                 sb.append(sep).append(param);
-                if (!m.isBridge() && !expect.equals(param)) {
+                if (!m.isBridge() && !m.getName().startsWith("lambda$") && !expect.equals(param)) {
                     error(prefix + "param[" + i + "]='"
                           + param + "' expected '" + expect + "'");
                     break;
--- a/test/tools/javac/lambda/8016177/T8016177g.java	Wed Apr 01 11:34:59 2015 -0700
+++ b/test/tools/javac/lambda/8016177/T8016177g.java	Thu Apr 09 22:59:11 2015 -0700
@@ -1,6 +1,6 @@
 /*
  * @test /nodynamiccopyright/
- * @bug 8016081 8016178
+ * @bug 8016081 8016178 8069545
  * @summary structural most specific and stuckness
  * @compile/fail/ref=T8016177g.out -XDrawDiagnostics T8016177g.java
  */
--- a/test/tools/javac/lambda/8016177/T8016177g.out	Wed Apr 01 11:34:59 2015 -0700
+++ b/test/tools/javac/lambda/8016177/T8016177g.out	Thu Apr 09 22:59:11 2015 -0700
@@ -1,2 +1,3 @@
-T8016177g.java:35:20: compiler.err.prob.found.req: (compiler.misc.possible.loss.of.precision: double, int)
-1 error
+T8016177g.java:34:14: compiler.err.cant.apply.symbol: kindname.method, print, java.lang.String, Test.Person, kindname.class, Test, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inferred.do.not.conform.to.upper.bounds: Test.Person, java.lang.String,java.lang.Object))
+T8016177g.java:35:20: compiler.err.cant.apply.symbol: kindname.method, abs, int, java.lang.Double, kindname.class, Test, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.infer.no.conforming.instance.exists: , R, int))
+2 errors
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/8068399/T8068399.java	Thu Apr 09 22:59:11 2015 -0700
@@ -0,0 +1,119 @@
+/*
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+/*
+ * @test
+ * @bug 8068399
+ * @summary structural most specific and stuckness
+ */
+
+import java.util.function.Function;
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+
+public class T8068399 {
+
+    public static class Spectrum {
+        public double[] getEnergy() {
+            return new double[0];
+        }
+    }
+
+    protected Spectrum spectrum;
+
+    public static class Ref<T> {
+
+        T value;
+
+        public Ref() {
+        }
+
+        public Ref(T value) {
+            this.value = value;
+        }
+
+        public boolean isNull() {
+            return value == null;
+        }
+
+        public T get() {
+            return value;
+        }
+
+        public void set(T value) {
+            this.value = value;
+        }
+    }
+
+    public static <T>T maxKey(Stream<T> stream, Function<T, Double> function) {
+        Ref<Double> max = new Ref<>();
+        Ref<T> index = new Ref<>();
+        stream.forEach(v -> {
+            Double value = function.apply(v);
+
+            if (max.isNull() || value > max.get()) {
+                max.set(value);
+                index.set(v);
+            }
+        });
+
+        return index.get();
+    }
+
+    public static int interpolate(int x, int x0, int x1, int y0, int y1) {
+        return y0 + (x - x0) * (y1 - y0) / (x1 - x0);
+    }
+
+    public static double interpolate(double x, double x0, double x1, double y0, double y1) {
+        return y0 + (x - x0) * (y1 - y0) / (x1 - x0);
+    }
+
+    protected int getXByFrequency(double frequency) {
+        return (int) Math.round(interpolate(frequency,
+                                            getMinSpectrumCoord(),
+                                            getMaxSpectrumCoord(),
+                                            0, getWidth()));
+    }
+
+    private int getWidth() {
+        return 0;
+    }
+
+    private double getMaxSpectrumCoord() {
+        return 0;
+    }
+
+    private double getMinSpectrumCoord() {
+        return 0;
+    }
+
+    void foo() {
+        int maxBpmIndex = 0;
+        int xcur = getXByFrequency(maxKey(IntStream.range(0, maxBpmIndex).boxed(),
+                                          i -> Math.abs(spectrum.getEnergy()[i])));
+    }
+
+    public static void main(String [] args) {
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/8068430/T8068430.java	Thu Apr 09 22:59:11 2015 -0700
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8068430
+ * @summary structural most specific and stuckness
+ */
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class T8068430 {
+    public static void main(String[] args) {
+        Map<Integer, String> mp = new HashMap<>();
+        mp.put(1, "a");
+        mp.put(2, "b");
+        mp.put(3, "c");
+        mp.put(4, "d");
+        System.out.println(mp.entrySet().stream().reduce(0,
+                (i, e) -> i + e.getKey(),
+                (i1, i2) -> i1 + i2));
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/8071432/T8071432.java	Thu Apr 09 22:59:11 2015 -0700
@@ -0,0 +1,50 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 8071432
+ * @summary structural most specific and stuckness
+ * @compile/fail/ref=T8071432.out -XDrawDiagnostics T8071432.java
+ */
+
+import java.util.Arrays;
+import java.util.Collection;
+
+class T8071432 {
+
+    static class Point {
+
+        private double x, y;
+
+        public Point(double x, double y) {
+            this.x = x;
+            this.y = y;
+        }
+
+        public double getX() {
+            return x;
+        }
+
+        public double getY() {
+            return y;
+        }
+
+        public double distance(Point p) {
+            return Math.sqrt((this.x - p.x) * (this.x - p.x) +
+                             (this.y - p.y) * (this.y - p.y));
+        }
+
+        public double distance() {
+            return Math.sqrt(this.x * this.x + this.y * this.y);
+        }
+
+        public String toString() {
+            return "(" + x + ":" + y + ")";
+        }
+    }
+
+    public static void main(String[] args) {
+        Collection<Point> c = Arrays.asList(new Point(1.0, 0.1));
+        System.out.println("------- 1 ---------------");
+        System.out.println(c.stream().reduce(0.0,
+                                            (s, p) -> s += p.distance(), (d1, d2) -> 0));
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/8071432/T8071432.out	Thu Apr 09 22:59:11 2015 -0700
@@ -0,0 +1,3 @@
+T8071432.java:47:45: compiler.err.prob.found.req: (compiler.misc.infer.no.conforming.assignment.exists: U, (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.inconvertible.types: int, java.lang.Double)))
+T8071432.java:47:27: compiler.err.cant.apply.symbol: kindname.method, println, java.lang.Object, <any>, kindname.class, java.io.PrintStream, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.infer.no.conforming.assignment.exists: U, (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.inconvertible.types: int, java.lang.Double))))
+2 errors
--- a/test/tools/javac/lambda/LocalVariableTable.java	Wed Apr 01 11:34:59 2015 -0700
+++ b/test/tools/javac/lambda/LocalVariableTable.java	Thu Apr 09 22:59:11 2015 -0700
@@ -23,7 +23,7 @@
 
 /*
  * @test
- * @bug 8025998 8026749
+ * @bug 8025998 8026749 8054220 8058227
  * @summary Missing LV table in lambda bodies
  * @compile -g LocalVariableTable.java
  * @run main LocalVariableTable
@@ -183,7 +183,7 @@
         Run1 r = (a) -> { int x = a; };
     }
 
-    @Expect({ "a", "x" })
+    @Expect({ "a", "x", "v" })
     static class Lambda_Args1_Local1_Captured1 {
         void m() {
             int v = 0;
@@ -191,7 +191,7 @@
         }
     }
 
-    @Expect({ "a1", "a2", "x1", "x2", "this" })
+    @Expect({ "a1", "a2", "x1", "x2", "this", "v1", "v2" })
     static class Lambda_Args2_Local2_Captured2_this {
         int v;
         void m() {
@@ -204,7 +204,7 @@
         }
     }
 
-    @Expect({ "e" })
+    @Expect({ "e", "c" })
     static class Lambda_Try_Catch {
         private static Runnable asUncheckedRunnable(Closeable c) {
             return () -> {