8030714: The steps attribute, flow and desugar are unnecessary for implicit classes when compiling with -implicit:none
authoralundblad
Thu, 13 Feb 2014 14:58:10 +0100
changeset 23115 97722ad6c874
parent 23114 7fe55d6324d5
child 23116 4c134ccd6b8d
8030714: The steps attribute, flow and desugar are unnecessary for implicit classes when compiling with -implicit:none Summary: When compiling with -implicit:none, attribute, flow and desugar is skipped for better performance. Reviewed-by: jfranck, jlahoda
langtools/src/share/classes/com/sun/tools/javac/comp/Todo.java
langtools/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java
langtools/test/tools/javac/implicitCompile/Implicit.java
langtools/test/tools/javac/implicitCompile/SkipAttrFlowGenForImplicits.java
langtools/test/tools/javac/implicitCompile/SkipAttrFlowGenForImplicits.out
--- a/langtools/src/share/classes/com/sun/tools/javac/comp/Todo.java	Thu Feb 13 13:38:48 2014 +0100
+++ b/langtools/src/share/classes/com/sun/tools/javac/comp/Todo.java	Thu Feb 13 14:58:10 2014 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2014, 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
@@ -26,7 +26,7 @@
 package com.sun.tools.javac.comp;
 
 import java.util.AbstractQueue;
-import com.sun.tools.javac.util.Context;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.LinkedList;
@@ -34,6 +34,8 @@
 import java.util.Queue;
 import javax.tools.JavaFileObject;
 
+import com.sun.tools.javac.util.Context;
+
 /** A queue of all as yet unattributed classes.
  *
  *  <p><b>This is NOT part of any supported API.
@@ -82,6 +84,22 @@
         }
     }
 
+    /**
+     * Removes all unattributed classes except those belonging to the given
+     * collection of files.
+     *
+     * @param sourceFiles The source files of the classes to keep.
+     */
+    public void retainFiles(Collection<? extends JavaFileObject> sourceFiles) {
+        for (Iterator<Env<AttrContext>> it = contents.iterator(); it.hasNext(); ) {
+            Env<AttrContext> env = it.next();
+            if (!sourceFiles.contains(env.toplevel.sourcefile)) {
+                if (contentsByFile != null) removeByFile(env);
+                it.remove();
+            }
+        }
+    }
+
     public Env<AttrContext> poll() {
         if (size() == 0)
             return null;
--- a/langtools/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java	Thu Feb 13 13:38:48 2014 +0100
+++ b/langtools/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java	Thu Feb 13 14:58:10 2014 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2014, 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
@@ -856,6 +856,12 @@
                     enterTrees(stopIfError(CompileState.PARSE, parseFiles(sourceFileObjects))),
                     classnames);
 
+            // If it's safe to do so, skip attr / flow / gen for implicit classes
+            if (taskListener.isEmpty() &&
+                    implicitSourcePolicy == ImplicitSourcePolicy.NONE) {
+                delegateCompiler.todo.retainFiles(delegateCompiler.inputFiles);
+            }
+
             delegateCompiler.compile2();
             delegateCompiler.close();
             elapsed_msec = delegateCompiler.elapsed_msec;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/implicitCompile/Implicit.java	Thu Feb 13 14:58:10 2014 +0100
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2014, 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.
+ */
+class Implicit {
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/implicitCompile/SkipAttrFlowGenForImplicits.java	Thu Feb 13 14:58:10 2014 +0100
@@ -0,0 +1,9 @@
+/*
+ * @test /nodynamiccopyright/
+ * @bug 8030714
+ * @summary make sure attribute and flow is skipped for implicit classes
+ * @compile/ref=SkipAttrFlowGenForImplicits.out -XDverboseCompilePolicy -implicit:none SkipAttrFlowGenForImplicits.java
+ */
+class Explicit {
+    Implicit implicit;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/langtools/test/tools/javac/implicitCompile/SkipAttrFlowGenForImplicits.out	Thu Feb 13 14:58:10 2014 +0100
@@ -0,0 +1,4 @@
+[attribute Explicit]
+[flow Explicit]
+[desugar Explicit]
+[generate code Explicit]