diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Todo.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Todo.java index eaeef34337..328aa442ef 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Todo.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Todo.java @@ -113,6 +113,10 @@ public Env peek() { return (size() == 0 ? null : contents.get(0)); } + public Queue> groupByFile(Env env) { + return new LinkedList<>(fileMap.get(env.toplevel.sourcefile)); + } + public Queue>> groupByFile() { if (contentsByFile == null) { contentsByFile = new LinkedList<>(); diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/main/JavaCompiler.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/main/JavaCompiler.java index 381de6a0dd..2af7c0bac1 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/main/JavaCompiler.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/main/JavaCompiler.java @@ -1511,11 +1511,17 @@ public void visitReference(JCMemberReference tree) { } ScanNested scanner = new ScanNested(); scanner.scan(env.tree); - for (Env dep: scanner.dependencies) { - if (!compileStates.isDone(dep, CompileState.FLOW)) - desugaredEnvs.put(dep, desugar(flow(attribute(dep)))); + if (compilePolicy == CompilePolicy.BY_FILE) { + desugarByFile(scanner.dependencies); + } else { + for (Env dep: scanner.dependencies) { + if (!compileStates.isDone(dep, CompileState.FLOW)) { + desugaredEnvs.put(dep, desugar(flow(attribute(dep)))); + } + } } + //We need to check for error another time as more classes might //have been attributed and analyzed at this stage if (shouldStop(CompileState.TRANSTYPES)) @@ -1593,6 +1599,20 @@ public void visitReference(JCMemberReference tree) { } } + // where + private void desugarByFile(Iterable> envs) { + Set seen = new HashSet<>(); + for (Env env: envs) { + if (compileStates.isDone(env, CompileState.FLOW)) { + continue; + } + if (seen.add(env.toplevel)) { + // process unique compilation units up to flow + flow(attribute(todo.groupByFile(env))); + } + desugaredEnvs.put(env, desugar(ListBuffer.of(env))); + } + } /** Generates the source or class file for a list of classes. * The decision to generate a source file or a class file is @@ -1652,20 +1672,6 @@ public void generate(Queue, JCClassDecl>> queue, Queue>> groupByFile(Queue> envs) { - // use a LinkedHashMap to preserve the order of the original list as much as possible - Map>> map = new LinkedHashMap<>(); - for (Env env: envs) { - Queue> sublist = map.get(env.toplevel); - if (sublist == null) { - sublist = new ListBuffer<>(); - map.put(env.toplevel, sublist); - } - sublist.add(env); - } - return map; - } - JCClassDecl removeMethodBodies(JCClassDecl cdef) { final boolean isInterface = (cdef.mods.flags & Flags.INTERFACE) != 0; class MethodBodyRemover extends TreeTranslator { diff --git a/test/langtools/tools/javac/policy/B27686620/A.java b/test/langtools/tools/javac/policy/B27686620/A.java new file mode 100644 index 0000000000..1306adf4de --- /dev/null +++ b/test/langtools/tools/javac/policy/B27686620/A.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2016, Google Inc. 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. + */ + +class A extends One {} diff --git a/test/langtools/tools/javac/policy/B27686620/B.java b/test/langtools/tools/javac/policy/B27686620/B.java new file mode 100644 index 0000000000..1c937b82e1 --- /dev/null +++ b/test/langtools/tools/javac/policy/B27686620/B.java @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2016, Google Inc. 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. + */ + +class One {} + +class Two {} diff --git a/test/langtools/tools/javac/policy/B27686620/B27686620.java b/test/langtools/tools/javac/policy/B27686620/B27686620.java new file mode 100644 index 0000000000..7f157494d8 --- /dev/null +++ b/test/langtools/tools/javac/policy/B27686620/B27686620.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2016, Google Inc. 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 + * @compile/ref=bytodo.ABC.out -XDverboseCompilePolicy -XDcompilePolicy=bytodo A.java B.java C.java + */ + +/* + * @test + * @compile/ref=byfile.ABC.out -XDverboseCompilePolicy -XDcompilePolicy=byfile A.java B.java C.java + */ + +/* + * @test + * @compile/ref=bytodo.ADC.out -XDverboseCompilePolicy -XDcompilePolicy=bytodo A.java D.java C.java + */ + +/* + * @test + * @compile/ref=byfile.ADC.out -XDverboseCompilePolicy -XDcompilePolicy=byfile A.java D.java C.java + */ + +/* + * @test + * @compile/ref=byfile.EF.out -XDverboseCompilePolicy -XDcompilePolicy=byfile E.java F.java + */ diff --git a/test/langtools/tools/javac/policy/B27686620/C.java b/test/langtools/tools/javac/policy/B27686620/C.java new file mode 100644 index 0000000000..0f279b86ce --- /dev/null +++ b/test/langtools/tools/javac/policy/B27686620/C.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2016, Google Inc. 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. + */ + +class B extends Two {} diff --git a/test/langtools/tools/javac/policy/B27686620/D.java b/test/langtools/tools/javac/policy/B27686620/D.java new file mode 100644 index 0000000000..6109bdc08f --- /dev/null +++ b/test/langtools/tools/javac/policy/B27686620/D.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2016, Google Inc. 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. + */ + +class One {} + +class Two {} + +class Three {} diff --git a/test/langtools/tools/javac/policy/B27686620/E.java b/test/langtools/tools/javac/policy/B27686620/E.java new file mode 100644 index 0000000000..a3e2f4779d --- /dev/null +++ b/test/langtools/tools/javac/policy/B27686620/E.java @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2016, Google Inc. 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. + */ + +class One {} + +class Two extends Four {} diff --git a/test/langtools/tools/javac/policy/B27686620/F.java b/test/langtools/tools/javac/policy/B27686620/F.java new file mode 100644 index 0000000000..106bfd1c0e --- /dev/null +++ b/test/langtools/tools/javac/policy/B27686620/F.java @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2016, Google Inc. 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. + */ + +class Three extends One {} + +class Four {} diff --git a/test/langtools/tools/javac/policy/B27686620/byfile.ABC.out b/test/langtools/tools/javac/policy/B27686620/byfile.ABC.out new file mode 100644 index 0000000000..c81be1948b --- /dev/null +++ b/test/langtools/tools/javac/policy/B27686620/byfile.ABC.out @@ -0,0 +1,16 @@ +[attribute A] +[flow A] +[attribute One] +[attribute Two] +[flow One] +[flow Two] +[desugar One] +[desugar A] +[generate code A] +[desugar Two] +[generate code One] +[generate code Two] +[attribute B] +[flow B] +[desugar B] +[generate code B] \ No newline at end of file diff --git a/test/langtools/tools/javac/policy/B27686620/byfile.ADC.out b/test/langtools/tools/javac/policy/B27686620/byfile.ADC.out new file mode 100644 index 0000000000..833fe6b0cb --- /dev/null +++ b/test/langtools/tools/javac/policy/B27686620/byfile.ADC.out @@ -0,0 +1,20 @@ +[attribute A] +[flow A] +[attribute One] +[attribute Two] +[attribute Three] +[flow One] +[flow Two] +[flow Three] +[desugar One] +[desugar A] +[generate code A] +[desugar Two] +[desugar Three] +[generate code One] +[generate code Two] +[generate code Three] +[attribute B] +[flow B] +[desugar B] +[generate code B] \ No newline at end of file diff --git a/test/langtools/tools/javac/policy/B27686620/byfile.EF.out b/test/langtools/tools/javac/policy/B27686620/byfile.EF.out new file mode 100644 index 0000000000..1dcc5e7399 --- /dev/null +++ b/test/langtools/tools/javac/policy/B27686620/byfile.EF.out @@ -0,0 +1,16 @@ +[attribute One] +[attribute Two] +[flow One] +[flow Two] +[desugar One] +[attribute Four] +[attribute Three] +[flow Four] +[flow Three] +[desugar Four] +[desugar Two] +[generate code One] +[generate code Two] +[desugar Three] +[generate code Four] +[generate code Three] \ No newline at end of file diff --git a/test/langtools/tools/javac/policy/B27686620/bytodo.ABC.out b/test/langtools/tools/javac/policy/B27686620/bytodo.ABC.out new file mode 100644 index 0000000000..1d47bd4e62 --- /dev/null +++ b/test/langtools/tools/javac/policy/B27686620/bytodo.ABC.out @@ -0,0 +1,16 @@ +[attribute A] +[flow A] +[attribute One] +[flow One] +[desugar One] +[desugar A] +[generate code A] +[generate code One] +[attribute Two] +[flow Two] +[desugar Two] +[generate code Two] +[attribute B] +[flow B] +[desugar B] +[generate code B] \ No newline at end of file diff --git a/test/langtools/tools/javac/policy/B27686620/bytodo.ADC.out b/test/langtools/tools/javac/policy/B27686620/bytodo.ADC.out new file mode 100644 index 0000000000..63f21fe0bf --- /dev/null +++ b/test/langtools/tools/javac/policy/B27686620/bytodo.ADC.out @@ -0,0 +1,20 @@ +[attribute A] +[flow A] +[attribute One] +[flow One] +[desugar One] +[desugar A] +[generate code A] +[generate code One] +[attribute Two] +[flow Two] +[desugar Two] +[generate code Two] +[attribute Three] +[flow Three] +[desugar Three] +[generate code Three] +[attribute B] +[flow B] +[desugar B] +[generate code B] \ No newline at end of file