OpenJDK / amber / amber
changeset 58365:48f8da9e2fd9 local-methods
8232763: [local-methods] Javac may invoke LambdaToMethod needlessly
author | sadayapalam |
---|---|
date | Tue, 22 Oct 2019 12:39:55 +0530 |
parents | 06d652252bc5 |
children | eecb73c873b5 |
files | src/jdk.compiler/share/classes/com/sun/tools/javac/main/JavaCompiler.java test/langtools/tools/javac/policy/test2/LocalMethodsL2MTest.java test/langtools/tools/javac/policy/test2/LocalMethodsL2MTest.out test/langtools/tools/javac/policy/test2/LocalMethodsNoL2MTest.java test/langtools/tools/javac/policy/test2/LocalMethodsNoL2MTest.out |
diffstat | 5 files changed, 118 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/main/JavaCompiler.java Mon Oct 21 15:38:47 2019 +0530 +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/main/JavaCompiler.java Tue Oct 22 12:39:55 2019 +0530 @@ -1478,31 +1478,37 @@ protected boolean inMethod; @Override public void visitClassDef(JCClassDecl node) { - Type st = types.supertype(node.sym.type); - boolean envForSuperTypeFound = false; - while (!envForSuperTypeFound && st.hasTag(CLASS)) { - ClassSymbol c = st.tsym.outermostClass(); - Env<AttrContext> stEnv = enter.getEnv(c); - if (stEnv != null && env != stEnv) { - if (dependencies.add(stEnv)) { - boolean prevHasLambdas = needsLambdaToMethod; - try { - scan(stEnv.tree); - } finally { - /* - * ignore any updates to needsLambdaToMethod made during - * the nested scan, this ensures an initalized - * LambdaToMethod is available only to those - * classes that contain lambdas - */ - needsLambdaToMethod = prevHasLambdas; + boolean prevInMethod = inMethod; + inMethod = false; + try { + Type st = types.supertype(node.sym.type); + boolean envForSuperTypeFound = false; + while (!envForSuperTypeFound && st.hasTag(CLASS)) { + ClassSymbol c = st.tsym.outermostClass(); + Env<AttrContext> stEnv = enter.getEnv(c); + if (stEnv != null && env != stEnv) { + if (dependencies.add(stEnv)) { + boolean prevNeedsLambdaToMethod = needsLambdaToMethod; + try { + scan(stEnv.tree); + } finally { + /* + * ignore any updates to needsLambdaToMethod made during + * the nested scan, this ensures an initalized + * LambdaToMethod is available only to those + * classes that contain lambdas + */ + needsLambdaToMethod = prevNeedsLambdaToMethod; + } } + envForSuperTypeFound = true; } - envForSuperTypeFound = true; + st = types.supertype(st); } - st = types.supertype(st); + super.visitClassDef(node); + } finally { + inMethod = prevInMethod; } - super.visitClassDef(node); } @Override public void visitLambda(JCLambda tree) { @@ -1578,6 +1584,9 @@ if (shouldStop(CompileState.UNLAMBDA)) return; + if (verboseCompilePolicy) + printNote("[LambdaToMethod " + env.enclClass.sym + "]"); + env.tree = LambdaToMethod.instance(context).translateTopLevelClass(env, env.tree, localMake); compileStates.put(env, CompileState.UNLAMBDA); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/langtools/tools/javac/policy/test2/LocalMethodsL2MTest.java Tue Oct 22 12:39:55 2019 +0530 @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2019, 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 8232763 + * @summary Javac may invoke LambdaToMethod needlessly + * @compile/ref=LocalMethodsL2MTest.out -XDverboseCompilePolicy LocalMethodsL2MTest.java + */ + +public class LocalMethodsL2MTest { + public void foo() { + class Inner { + void goo() { + void zoo() {} + } + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/langtools/tools/javac/policy/test2/LocalMethodsL2MTest.out Tue Oct 22 12:39:55 2019 +0530 @@ -0,0 +1,6 @@ +[attribute LocalMethodsL2MTest] +[flow LocalMethodsL2MTest] +[desugar LocalMethodsL2MTest] +[LambdaToMethod LocalMethodsL2MTest] +[generate code Inner] +[generate code LocalMethodsL2MTest]
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/langtools/tools/javac/policy/test2/LocalMethodsNoL2MTest.java Tue Oct 22 12:39:55 2019 +0530 @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2019, 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 8232763 + * @summary Javac may invoke LambdaToMethod needlessly + * @compile/ref=LocalMethodsNoL2MTest.out -XDverboseCompilePolicy LocalMethodsNoL2MTest.java + */ + +public class LocalMethodsNoL2MTest { + public void foo() { + class Inner { + void goo() { + } + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/langtools/tools/javac/policy/test2/LocalMethodsNoL2MTest.out Tue Oct 22 12:39:55 2019 +0530 @@ -0,0 +1,5 @@ +[attribute LocalMethodsNoL2MTest] +[flow LocalMethodsNoL2MTest] +[desugar LocalMethodsNoL2MTest] +[generate code Inner] +[generate code LocalMethodsNoL2MTest]