changeset 3358:3ab9841babb7 icedtea-3.3.0pre01

Merge jdk8u112-b16
author andrew
date Thu, 12 Jan 2017 06:59:37 +0000
parents 56b10dbfe87e (current diff) ee37eafc48cb (diff)
children fcc9b17c0dc1
files .hgtags
diffstat 11 files changed, 702 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/.hgtags	Tue Nov 08 05:26:14 2016 +0000
+++ b/.hgtags	Thu Jan 12 06:59:37 2017 +0000
@@ -670,3 +670,19 @@
 8e5e70b9cff8f928d28db4890d4e5905a739d210 jdk8u111-b12
 ef3134b243da77d0aed9f3cef2b3855c3be2111a jdk8u111-b13
 a553c153d37671a371767229c71189d963964996 icedtea-3.2.0
+0e2e745ed6d7bb8a2233e83f4bad40e793a16949 jdk8u111-b14
+27503e49de52b54dde3a12af28e2d2de473192b3 jdk8u112-b00
+60a0572cd449e33b7d48b5a40065222ab5accd36 jdk8u112-b01
+6e20b82db75fbaf5a3e10455d1a28c17381f4be6 jdk8u112-b02
+e87830f756786db50d89d77ee802f303cf42d0b1 jdk8u112-b03
+03a192ef78d0ea77f1141174b29835b702f86793 jdk8u112-b04
+27a15af81178d312748a45efa457e5ef1a76e088 jdk8u112-b06
+35cb56e983d317fd319d2dbb17282264edea02e2 jdk8u112-b07
+103e6e2225bbbe779435b2e122e1ff846be54759 jdk8u112-b08
+ea5711153422cc1f8d710de08b7f4dc9e20b9333 jdk8u112-b09
+96658afeb900cb1bfc6c56b352745f3ede0ee524 jdk8u112-b10
+0169856d09008e5718f53a5d6c16e7db95c55887 jdk8u112-b11
+f56f9368471aa5bc949a730e2724ceb68e90d717 jdk8u112-b12
+04d857308b8c3db33e8fd4099c3a3dd5d50cdaeb jdk8u112-b13
+b353281f73db9617d993353e468342d3420c29f1 jdk8u112-b14
+6116c6644be0c85556931aaeb9b4f2dbc9c79157 jdk8u112-b15
--- a/LICENSE	Tue Nov 08 05:26:14 2016 +0000
+++ b/LICENSE	Thu Jan 12 06:59:37 2017 +0000
@@ -3,7 +3,7 @@
 Version 2, June 1991
 
 Copyright (C) 1989, 1991 Free Software Foundation, Inc.
-59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
 Everyone is permitted to copy and distribute verbatim copies of this license
 document, but changing it is not allowed.
@@ -287,8 +287,8 @@
     more details.
 
     You should have received a copy of the GNU General Public License along
-    with this program; if not, write to the Free Software Foundation, Inc., 59
-    Temple Place, Suite 330, Boston, MA 02111-1307 USA
+    with this program; if not, write to the Free Software Foundation, Inc.,
+    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
 Also add information on how to contact you by electronic and paper mail.
 
--- a/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java	Tue Nov 08 05:26:14 2016 +0000
+++ b/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java	Thu Jan 12 06:59:37 2017 +0000
@@ -338,6 +338,11 @@
                 syntheticInits.append((JCExpression) captured_local);
             }
         }
+        // add captured outer this instances (used only when `this' capture itself is illegal)
+        for (Symbol fv : localContext.getSymbolMap(CAPTURED_OUTER_THIS).keySet()) {
+            JCTree captured_local = make.QualThis(fv.type);
+            syntheticInits.append((JCExpression) captured_local);
+        }
 
         //then, determine the arguments to the indy call
         List<JCExpression> indy_args = translate(syntheticInits.toList(), localContext.prev);
@@ -434,6 +439,32 @@
         }
     }
 
+    /**
+     * Translate qualified `this' references within a lambda to the mapped identifier
+     * @param tree
+     */
+    @Override
+    public void visitSelect(JCFieldAccess tree) {
+        if (context == null || !analyzer.lambdaFieldAccessFilter(tree)) {
+            super.visitSelect(tree);
+        } else {
+            int prevPos = make.pos;
+            try {
+                make.at(tree);
+
+                LambdaTranslationContext lambdaContext = (LambdaTranslationContext) context;
+                JCTree ltree = lambdaContext.translate(tree);
+                if (ltree != null) {
+                    result = ltree;
+                } else {
+                    super.visitSelect(tree);
+                }
+            } finally {
+                make.at(prevPos);
+            }
+        }
+    }
+
     @Override
     public void visitVarDef(JCVariableDecl tree) {
         LambdaTranslationContext lambdaContext = (LambdaTranslationContext)context;
@@ -1126,6 +1157,11 @@
         private int lambdaCount = 0;
 
         /**
+         * List of types undergoing construction via explicit constructor chaining.
+         */
+        private List<ClassSymbol> typesUnderConstruction;
+
+        /**
          * keep the count of lambda expression defined in given context (used to
          * generate unambiguous names for serializable lambdas)
          */
@@ -1156,11 +1192,36 @@
 
         private JCClassDecl analyzeAndPreprocessClass(JCClassDecl tree) {
             frameStack = List.nil();
+            typesUnderConstruction = List.nil();
             localClassDefs = new HashMap<Symbol, JCClassDecl>();
             return translate(tree);
         }
 
         @Override
+        public void visitApply(JCMethodInvocation tree) {
+            List<ClassSymbol> previousNascentTypes = typesUnderConstruction;
+            try {
+                Name methName = TreeInfo.name(tree.meth);
+                if (methName == names._this || methName == names._super) {
+                    typesUnderConstruction = typesUnderConstruction.prepend(currentClass());
+                }
+                super.visitApply(tree);
+            } finally {
+                typesUnderConstruction = previousNascentTypes;
+            }
+        }
+            // where
+            private ClassSymbol currentClass() {
+                for (Frame frame : frameStack) {
+                    if (frame.tree.hasTag(JCTree.Tag.CLASSDEF)) {
+                        JCClassDecl cdef = (JCClassDecl) frame.tree;
+                        return cdef.sym;
+                    }
+                }
+                return null;
+            }
+
+        @Override
         public void visitBlock(JCBlock tree) {
             List<Frame> prevStack = frameStack;
             try {
@@ -1624,6 +1685,22 @@
         }
 
         /**
+         *  This is used to filter out those select nodes that need to be adjusted
+         *  when translating away lambda expressions - at the moment, this is the
+         *  set of nodes that select `this' (qualified this)
+         */
+        private boolean lambdaFieldAccessFilter(JCFieldAccess fAccess) {
+            LambdaTranslationContext lambdaContext =
+                    context instanceof LambdaTranslationContext ?
+                            (LambdaTranslationContext) context : null;
+            return lambdaContext != null
+                    && !fAccess.sym.isStatic()
+                    && fAccess.name == names._this
+                    && (fAccess.sym.owner.kind == TYP)
+                    && !lambdaContext.translatedSymbols.get(CAPTURED_OUTER_THIS).isEmpty();
+        }
+
+        /**
          * This is used to filter out those new class expressions that need to
          * be qualified with an enclosing tree
          */
@@ -1797,6 +1874,7 @@
                 translatedSymbols.put(LOCAL_VAR, new LinkedHashMap<Symbol, Symbol>());
                 translatedSymbols.put(CAPTURED_VAR, new LinkedHashMap<Symbol, Symbol>());
                 translatedSymbols.put(CAPTURED_THIS, new LinkedHashMap<Symbol, Symbol>());
+                translatedSymbols.put(CAPTURED_OUTER_THIS, new LinkedHashMap<Symbol, Symbol>());
                 translatedSymbols.put(TYPE_VAR, new LinkedHashMap<Symbol, Symbol>());
 
                 freeVarProcessedLocalClasses = new HashSet<>();
@@ -1909,6 +1987,16 @@
                             }
                         };
                         break;
+                    case CAPTURED_OUTER_THIS:
+                        Name name = names.fromString(new String(sym.flatName().toString() + names.dollarThis));
+                        ret = new VarSymbol(SYNTHETIC | FINAL | PARAMETER, name, types.erasure(sym.type), translatedSym) {
+                            @Override
+                            public Symbol baseSymbol() {
+                                //keep mapping with original captured symbol
+                                return sym;
+                            }
+                        };
+                        break;
                     case LOCAL_VAR:
                         ret = new VarSymbol(sym.flags() & FINAL, sym.name, sym.type, translatedSym);
                         ((VarSymbol) ret).pos = ((VarSymbol) sym).pos;
@@ -1929,6 +2017,14 @@
             }
 
             void addSymbol(Symbol sym, LambdaSymbolKind skind) {
+                if (skind == CAPTURED_THIS && sym != null && sym.kind == TYP && !typesUnderConstruction.isEmpty()) {
+                    ClassSymbol currentClass = currentClass();
+                    if (currentClass != null && typesUnderConstruction.contains(currentClass)) {
+                        // reference must be to enclosing outer instance, mutate capture kind.
+                        Assert.check(sym != currentClass); // should have been caught right in Attr
+                        skind = CAPTURED_OUTER_THIS;
+                    }
+                }
                 Map<Symbol, Symbol> transMap = getSymbolMap(skind);
                 if (!transMap.containsKey(sym)) {
                     transMap.put(sym, translate(sym, skind));
@@ -1942,17 +2038,49 @@
             }
 
             JCTree translate(JCIdent lambdaIdent) {
-                for (Map<Symbol, Symbol> m : translatedSymbols.values()) {
-                    if (m.containsKey(lambdaIdent.sym)) {
-                        Symbol tSym = m.get(lambdaIdent.sym);
-                        JCTree t = make.Ident(tSym).setType(lambdaIdent.type);
-                        tSym.setTypeAttributes(lambdaIdent.sym.getRawTypeAttributes());
-                        return t;
+                for (LambdaSymbolKind kind : LambdaSymbolKind.values()) {
+                    Map<Symbol, Symbol> m = getSymbolMap(kind);
+                    switch(kind) {
+                        default:
+                            if (m.containsKey(lambdaIdent.sym)) {
+                                Symbol tSym = m.get(lambdaIdent.sym);
+                                JCTree t = make.Ident(tSym).setType(lambdaIdent.type);
+                                tSym.setTypeAttributes(lambdaIdent.sym.getRawTypeAttributes());
+                                return t;
+                            }
+                            break;
+                        case CAPTURED_OUTER_THIS:
+                            if (lambdaIdent.sym.owner.kind == TYP && m.containsKey(lambdaIdent.sym.owner)) {
+                                // Transform outer instance variable references anchoring them to the captured synthetic.
+                                Symbol tSym = m.get(lambdaIdent.sym.owner);
+                                JCExpression t = make.Ident(tSym).setType(lambdaIdent.sym.owner.type);
+                                tSym.setTypeAttributes(lambdaIdent.sym.owner.getRawTypeAttributes());
+                                t = make.Select(t, lambdaIdent.name);
+                                t.setType(lambdaIdent.type);
+                                TreeInfo.setSymbol(t, lambdaIdent.sym);
+                                return t;
+                            }
+                            break;
                     }
                 }
                 return null;
             }
 
+            /* Translate away qualified this expressions, anchoring them to synthetic parameters that
+               capture the qualified this handle. `fieldAccess' is guaranteed to one such.
+            */
+            public JCTree translate(JCFieldAccess fieldAccess) {
+                Assert.check(fieldAccess.name == names._this);
+                Map<Symbol, Symbol> m = translatedSymbols.get(LambdaSymbolKind.CAPTURED_OUTER_THIS);
+                if (m.containsKey(fieldAccess.sym.owner)) {
+                    Symbol tSym = m.get(fieldAccess.sym.owner);
+                    JCExpression t = make.Ident(tSym).setType(fieldAccess.sym.owner.type);
+                    tSym.setTypeAttributes(fieldAccess.sym.owner.getRawTypeAttributes());
+                    return t;
+                }
+                return null;
+            }
+
             /**
              * The translatedSym is not complete/accurate until the analysis is
              * finished.  Once the analysis is finished, the translatedSym is
@@ -1990,6 +2118,10 @@
                     params.append(make.VarDef((VarSymbol) thisSym, null));
                     parameterSymbols.append((VarSymbol) thisSym);
                 }
+                for (Symbol thisSym : getSymbolMap(CAPTURED_OUTER_THIS).values()) {
+                    params.append(make.VarDef((VarSymbol) thisSym, null));
+                    parameterSymbols.append((VarSymbol) thisSym);
+                }
                 for (Symbol thisSym : getSymbolMap(PARAM).values()) {
                     params.append(make.VarDef((VarSymbol) thisSym, null));
                     parameterSymbols.append((VarSymbol) thisSym);
@@ -2138,6 +2270,7 @@
         LOCAL_VAR,      // original to translated lambda locals
         CAPTURED_VAR,   // variables in enclosing scope to translated synthetic parameters
         CAPTURED_THIS,  // class symbols to translated synthetic parameters (for captured member access)
+        CAPTURED_OUTER_THIS, // used when `this' capture is illegal, but outer this capture is legit (JDK-8129740)
         TYPE_VAR;       // original to translated lambda type variables
     }
 
--- a/src/share/classes/com/sun/tools/javac/tree/TreeMaker.java	Tue Nov 08 05:26:14 2016 +0000
+++ b/src/share/classes/com/sun/tools/javac/tree/TreeMaker.java	Thu Jan 12 06:59:37 2017 +0000
@@ -621,6 +621,12 @@
         return Ident(new VarSymbol(FINAL, names._this, t, t.tsym));
     }
 
+    /** Create a tree representing qualified `this' given its type
+     */
+    public JCExpression QualThis(Type t) {
+        return Select(Type(t), new VarSymbol(FINAL, names._this, t, t.tsym));
+    }
+
     /** Create a tree representing a class literal.
      */
     public JCExpression ClassLiteral(ClassSymbol clazz) {
--- a/src/share/classes/com/sun/tools/javac/util/Names.java	Tue Nov 08 05:26:14 2016 +0000
+++ b/src/share/classes/com/sun/tools/javac/util/Names.java	Thu Jan 12 06:59:37 2017 +0000
@@ -176,6 +176,7 @@
     public final Name lambda;
     public final Name metafactory;
     public final Name altMetafactory;
+    public final Name dollarThis;
 
     public final Name.Table table;
 
@@ -234,6 +235,7 @@
         value = fromString("value");
         valueOf = fromString("valueOf");
         values = fromString("values");
+        dollarThis = fromString("$this");
 
         // class names
         java_io_Serializable = fromString("java.io.Serializable");
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/T8129740/AllowEnclosingVarCaptureTest.java	Thu Jan 12 06:59:37 2017 +0000
@@ -0,0 +1,59 @@
+/*
+ * 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.
+ *
+ * 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 8129740 8133111 8157142
+ * @summary Incorrect class file created when passing lambda in inner class constructor
+ * @run main AllowEnclosingVarCaptureTest
+ */
+
+public class AllowEnclosingVarCaptureTest {
+
+    int var = 0;
+
+    void foo() {
+        var *= 2;
+    }
+
+    public static void main(String[] args) {
+        new AllowEnclosingVarCaptureTest().new Inner(9764);
+    }
+
+    public class Inner {
+        public Inner(Runnable r) {
+            r.run();
+            if (var != 66704)
+                throw new AssertionError("Unexpected output: " + var);
+        }
+
+        public Inner(int x) {
+            this(() -> {
+                var = x + 1234;
+                AllowEnclosingVarCaptureTest.this.var += 5678;
+                foo();
+                AllowEnclosingVarCaptureTest.this.foo();
+            });
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/T8129740/CaptureInCtorChainingTest.java	Thu Jan 12 06:59:37 2017 +0000
@@ -0,0 +1,54 @@
+/*
+ * 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.
+ *
+ * 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 8129740 8133111 8157142
+ * @summary Incorrect class file created when passing lambda in inner class constructor
+ * @run main CaptureInCtorChainingTest
+ */
+
+import java.util.function.Consumer;
+import java.util.function.Function;
+
+public class CaptureInCtorChainingTest {
+
+    CaptureInCtorChainingTest(Function<Function<Function<Consumer<Void>, Void>, Void>, Void> innerClass) {
+        new InnerClass(innerClass);
+    }
+
+    void foo(Void v) { }
+
+    class InnerClass {
+
+        InnerClass(Function<Function<Function<Consumer<Void>, Void>, Void>, Void> factory) {
+            this(factory.apply(o -> o.apply(CaptureInCtorChainingTest.this::foo)));
+        }
+
+        InnerClass(Void unused) { }
+    }
+
+    public static void main(String[] args) {
+        new CaptureInCtorChainingTest(o -> null);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/T8129740/QualifiedThisAccessTest.java	Thu Jan 12 06:59:37 2017 +0000
@@ -0,0 +1,157 @@
+/*
+ * 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.
+ *
+ * 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 8129740 8133111 8157142
+ * @summary Incorrect class file created when passing lambda in inner class constructor
+ * @run main QualifiedThisAccessTest
+ */
+
+public class QualifiedThisAccessTest { // Not referenced by lambda, so should not be captured.
+
+    public class Universe { // Not referenced by lambda, so should not be captured.
+
+        public String name;
+        public int galaxiesCount;
+
+        public Universe(String name, int galaxiesCount) {
+            this.name = name;
+            this.galaxiesCount = galaxiesCount;
+        }
+
+        public String toString() {
+            return "Universe" + name + " of " + galaxiesCount + " galaxies";
+        }
+
+        class Galaxy {
+
+            String name;
+            private int starsCount;
+
+            Galaxy(String name, int starsCount) {
+                this.name = name;
+                this.starsCount = starsCount;
+            }
+
+            public String toString() {
+                return "galaxy " + name + " of " + starsCount + " solar systems";
+            }
+
+            int starsCount() {
+                return starsCount;
+            }
+
+            private String name() {
+                return name;
+            }
+
+            class SolarSystem {
+
+                String name;
+                int planetsCount;
+
+                SolarSystem(String name, int planetsCount) {
+                    this.name = name;
+                    this.planetsCount = planetsCount;
+                }
+
+                public String toString() {
+                    return "Solar System of " + name + " with " + planetsCount + " planets";
+                }
+
+                int planetsCount() {
+                    return planetsCount;
+                }
+
+                SolarSystem copy(SolarSystem s) {
+                    return s;
+                }
+
+                class Planet {
+
+                    String name;
+                    int moonsCount;
+
+                    Planet(String name, int moonsCount, Runnable r) {
+                        this.name = name;
+                        this.moonsCount = moonsCount;
+                        r.run();
+                    }
+                    Planet (String name, int moonsCount) {
+                        this(name, moonsCount, ()-> {
+                            StringBuffer buf = new StringBuffer();
+                            buf.append("This planet belongs to the galaxy "
+                                        + Galaxy.this.name + " with " + starsCount + " stars\n");
+                            buf.append("This planet belongs to the galaxy "
+                                        + Universe.Galaxy.this.name + " with " + starsCount() + " stars\n");
+                            buf.append("This planet belongs to the galaxy "
+                                        + Galaxy.this.name() + " with " + starsCount() + " stars\n");
+                            buf.append("This planet belongs to the galaxy "
+                                        + Universe.Galaxy.this.name() + " with "
+                                        + (Universe.Galaxy.this).starsCount() + " stars\n");
+
+                            buf.append("This planet belongs to the solar system "
+                                        + SolarSystem.this.name + " with " + planetsCount + " planets\n");
+                            buf.append("This planet belongs to the solar system "
+                                        + Galaxy.SolarSystem.this.name + " with " + planetsCount() + " planets\n");
+                            buf.append("This planet belongs to the solar system "
+                                        + (SolarSystem.this).name + " with " + planetsCount + " planets\n");
+                            buf.append("This planet belongs to the solar system "
+                                        + Universe.Galaxy.SolarSystem.this.name + " with "
+                                        + Universe.Galaxy.SolarSystem.this.planetsCount + " planets\n");
+                            buf.append("This planet belongs to the solar system "
+                                        + Universe.Galaxy.SolarSystem.this.name.toLowerCase().toUpperCase()
+                                        + " with " + Universe.Galaxy.SolarSystem.this.planetsCount + " planets\n");
+                            buf.append("This planet belongs to the solar system "
+                                        + copy(Universe.Galaxy.SolarSystem.this).name.toLowerCase().toUpperCase()
+                                        + " with " + Universe.Galaxy.SolarSystem.this.planetsCount + " planets\n");
+                            if (!buf.toString().equals(output))
+                                throw new AssertionError("Unexpected value\n" + buf);
+                        });
+                    }
+
+                    static final String output =
+                        "This planet belongs to the galaxy Mily way with 23456789 stars\n" +
+                        "This planet belongs to the galaxy Mily way with 23456789 stars\n" +
+                        "This planet belongs to the galaxy Mily way with 23456789 stars\n" +
+                        "This planet belongs to the galaxy Mily way with 23456789 stars\n" +
+                        "This planet belongs to the solar system Sun with 9 planets\n" +
+                        "This planet belongs to the solar system Sun with 9 planets\n" +
+                        "This planet belongs to the solar system Sun with 9 planets\n" +
+                        "This planet belongs to the solar system Sun with 9 planets\n" +
+                        "This planet belongs to the solar system SUN with 9 planets\n" +
+                        "This planet belongs to the solar system SUN with 9 planets\n";
+
+
+                    public String toString() {
+                        return "Planet " + name + " with " + moonsCount + " moon(s)";
+                    }
+                }
+            }
+        }
+    }
+    public static void main(String[] args) {
+        new QualifiedThisAccessTest().new Universe("Universe", 12345678).new Galaxy("Mily way", 23456789).new SolarSystem("Sun", 9).new Planet("Earth", 1);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/T8129740/SourceForTranslation.java	Thu Jan 12 06:59:37 2017 +0000
@@ -0,0 +1,122 @@
+    class Universe { // Not referenced by lambda, so should not be captured.
+
+        public String name;
+        public int galaxiesCount;
+
+        public Universe(String name, int galaxiesCount) {
+            this.name = name;
+            this.galaxiesCount = galaxiesCount;
+        }
+
+        public String toString() {
+            return "Universe" + name + " of " + galaxiesCount + " galaxies";
+        }
+
+        class Galaxy {
+
+            String name;
+            private int starsCount;
+
+            Galaxy(String name, int starsCount) {
+                this.name = name;
+                this.starsCount = starsCount;
+            }
+
+            public String toString() {
+                return "galaxy " + name + " of " + starsCount + " solar systems";
+            }
+
+            int starsCount() {
+                return starsCount;
+            }
+
+            private String name() {
+                return name;
+            }
+
+            class SolarSystem {
+
+                String name;
+                int planetsCount;
+
+                SolarSystem(String name, int planetsCount) {
+                    this.name = name;
+                    this.planetsCount = planetsCount;
+                }
+
+                public String toString() {
+                    return "Solar System of " + name + " with " + planetsCount + " planets";
+                }
+
+                int planetsCount() {
+                    return planetsCount;
+                }
+
+                SolarSystem copy(SolarSystem s) {
+                    return s;
+                }
+
+                class Planet {
+
+                    String name;
+                    int moonsCount;
+
+                    Planet(String name, int moonsCount, Runnable r) {
+                        this.name = name;
+                        this.moonsCount = moonsCount;
+                        r.run();
+                    }
+                    Planet (String name, int moonsCount) {
+                        this(name, moonsCount, ()-> {
+                            String n = name;
+                            StringBuffer buf = new StringBuffer();
+                            buf.append("This planet belongs to the galaxy "
+                                        + Galaxy.this.name + " with " + starsCount + " stars\n");
+                            buf.append("This planet belongs to the galaxy "
+                                        + Universe.Galaxy.this.name + " with " + starsCount() + " stars\n");
+                            buf.append("This planet belongs to the galaxy "
+                                        + Galaxy.this.name() + " with " + starsCount() + " stars\n");
+                            buf.append("This planet belongs to the galaxy "
+                                        + Universe.Galaxy.this.name() + " with "
+                                        + (Universe.Galaxy.this).starsCount() + " stars\n");
+
+                            buf.append("This planet belongs to the solar system "
+                                        + SolarSystem.this.name + " with " + planetsCount + " planets\n");
+                            buf.append("This planet belongs to the solar system "
+                                        + Galaxy.SolarSystem.this.name + " with " + planetsCount() + " planets\n");
+                            buf.append("This planet belongs to the solar system "
+                                        + (SolarSystem.this).name + " with " + planetsCount + " planets\n");
+                            buf.append("This planet belongs to the solar system "
+                                        + Universe.Galaxy.SolarSystem.this.name + " with "
+                                        + Universe.Galaxy.SolarSystem.this.planetsCount + " planets\n");
+                            buf.append("This planet belongs to the solar system "
+                                        + Universe.Galaxy.SolarSystem.this.name.toLowerCase().toUpperCase()
+                                        + " with " + Universe.Galaxy.SolarSystem.this.planetsCount + " planets\n");
+                            buf.append("This planet belongs to the solar system "
+                                        + copy(Universe.Galaxy.SolarSystem.this).name.toLowerCase().toUpperCase()
+                                        + " with " + Universe.Galaxy.SolarSystem.this.planetsCount + " planets\n");
+                            if (!buf.toString().equals(output))
+                                throw new AssertionError("Unexpected value\n" + buf);
+                        });
+                    }
+
+                    static final String output =
+                        "This planet belongs to the galaxy Mily way with 23456789 stars\n" +
+                        "This planet belongs to the galaxy Mily way with 23456789 stars\n" +
+                        "This planet belongs to the galaxy Mily way with 23456789 stars\n" +
+                        "This planet belongs to the galaxy Mily way with 23456789 stars\n" +
+                        "This planet belongs to the solar system Sun with 9 planets\n" +
+                        "This planet belongs to the solar system Sun with 9 planets\n" +
+                        "This planet belongs to the solar system Sun with 9 planets\n" +
+                        "This planet belongs to the solar system Sun with 9 planets\n" +
+                        "This planet belongs to the solar system SUN with 9 planets\n" +
+                        "This planet belongs to the solar system SUN with 9 planets\n";
+
+
+                    public String toString() {
+                        return "Planet " + name + " with " + moonsCount + " moon(s)";
+                    }
+                }
+            }
+        }
+    }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/T8129740/SourceToSourceTranslationTest.java	Thu Jan 12 06:59:37 2017 +0000
@@ -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.
+ *
+ * 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 8129740 8133111 8157142
+ * @summary Incorrect class file created when passing lambda in inner class constructor
+ * @library /tools/javac/lib
+ * @build ToolBox
+ * @run compile -XD-printsource SourceForTranslation.java
+ * @run main SourceToSourceTranslationTest
+ */
+
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.List;
+
+public class SourceToSourceTranslationTest {
+
+    public static void main(String[] args) throws Exception {
+        Path path1 = Paths.get(System.getProperty("test.classes"), "Universe.java");
+        Path path2 = Paths.get(System.getProperty("test.src"), "Universe.java.out");
+        ToolBox.compareLines(path1, path2, null);
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/lambda/T8129740/Universe.java.out	Thu Jan 12 06:59:37 2017 +0000
@@ -0,0 +1,98 @@
+
+class Universe {
+    public String name;
+    public int galaxiesCount;
+    
+    public Universe(String name, int galaxiesCount) {
+        super();
+        this.name = name;
+        this.galaxiesCount = galaxiesCount;
+    }
+    
+    public String toString() {
+        return "Universe" + name + " of " + galaxiesCount + " galaxies";
+    }
+    
+    class Galaxy {
+        String name;
+        private int starsCount;
+        
+        Galaxy(String name, int starsCount) {
+            super();
+            this.name = name;
+            this.starsCount = starsCount;
+        }
+        
+        public String toString() {
+            return "galaxy " + name + " of " + starsCount + " solar systems";
+        }
+        
+        int starsCount() {
+            return starsCount;
+        }
+        
+        private String name() {
+            return name;
+        }
+        
+        class SolarSystem {
+            String name;
+            int planetsCount;
+            
+            SolarSystem(String name, int planetsCount) {
+                super();
+                this.name = name;
+                this.planetsCount = planetsCount;
+            }
+            
+            public String toString() {
+                return "Solar System of " + name + " with " + planetsCount + " planets";
+            }
+            
+            int planetsCount() {
+                return planetsCount;
+            }
+            
+            SolarSystem copy(SolarSystem s) {
+                return s;
+            }
+            
+            class Planet {
+                String name;
+                int moonsCount;
+                
+                Planet(String name, int moonsCount, Runnable r) {
+                    super();
+                    this.name = name;
+                    this.moonsCount = moonsCount;
+                    r.run();
+                }
+                
+                Planet(String name, int moonsCount) {
+                    this(name, moonsCount, java.lang.invoke.LambdaMetafactory.metafactory(name, Universe.Galaxy.this, Universe.Galaxy.SolarSystem.this));
+                }
+                static final String output = "This planet belongs to the galaxy Mily way with 23456789 stars\nThis planet belongs to the galaxy Mily way with 23456789 stars\nThis planet belongs to the galaxy Mily way with 23456789 stars\nThis planet belongs to the galaxy Mily way with 23456789 stars\nThis planet belongs to the solar system Sun with 9 planets\nThis planet belongs to the solar system Sun with 9 planets\nThis planet belongs to the solar system Sun with 9 planets\nThis planet belongs to the solar system Sun with 9 planets\nThis planet belongs to the solar system SUN with 9 planets\nThis planet belongs to the solar system SUN with 9 planets\n";
+                
+                public String toString() {
+                    return "Planet " + name + " with " + moonsCount + " moon(s)";
+                }
+                
+                /*synthetic*/ private static void lambda$new$0(/*synthetic*/ final String name, /*synthetic*/ final Universe.Galaxy Universe$Galaxy$this, /*synthetic*/ final Universe.Galaxy.SolarSystem Universe$Galaxy$SolarSystem$this) {
+                    String n = name;
+                    StringBuffer buf = new StringBuffer();
+                    buf.append("This planet belongs to the galaxy " + Universe$Galaxy$this.name + " with " + Universe$Galaxy$this.starsCount + " stars\n");
+                    buf.append("This planet belongs to the galaxy " + Universe$Galaxy$this.name + " with " + Universe$Galaxy$this.starsCount() + " stars\n");
+                    buf.append("This planet belongs to the galaxy " + Universe$Galaxy$this.name() + " with " + Universe$Galaxy$this.starsCount() + " stars\n");
+                    buf.append("This planet belongs to the galaxy " + Universe$Galaxy$this.name() + " with " + (Universe$Galaxy$this).starsCount() + " stars\n");
+                    buf.append("This planet belongs to the solar system " + Universe$Galaxy$SolarSystem$this.name + " with " + Universe$Galaxy$SolarSystem$this.planetsCount + " planets\n");
+                    buf.append("This planet belongs to the solar system " + Universe$Galaxy$SolarSystem$this.name + " with " + Universe$Galaxy$SolarSystem$this.planetsCount() + " planets\n");
+                    buf.append("This planet belongs to the solar system " + (Universe$Galaxy$SolarSystem$this).name + " with " + Universe$Galaxy$SolarSystem$this.planetsCount + " planets\n");
+                    buf.append("This planet belongs to the solar system " + Universe$Galaxy$SolarSystem$this.name + " with " + Universe$Galaxy$SolarSystem$this.planetsCount + " planets\n");
+                    buf.append("This planet belongs to the solar system " + Universe$Galaxy$SolarSystem$this.name.toLowerCase().toUpperCase() + " with " + Universe$Galaxy$SolarSystem$this.planetsCount + " planets\n");
+                    buf.append("This planet belongs to the solar system " + Universe$Galaxy$SolarSystem$this.copy(Universe$Galaxy$SolarSystem$this).name.toLowerCase().toUpperCase() + " with " + Universe$Galaxy$SolarSystem$this.planetsCount + " planets\n");
+                    if (!buf.toString().equals(output)) throw new AssertionError("Unexpected value\n" + buf);
+                }
+            }
+        }
+    }
+}