8030714: The steps attribute, flow and desugar are unnecessary for implicit classes when compiling with -implicit:none

When compiling with -implicit:none, attribute, flow and desugar is skipped for better performance.

Reviewed-by: jfranck, jlahoda
This commit is contained in:
Andreas Lundblad 2014-02-13 14:58:10 +01:00
parent e20546fe2a
commit 8daec20c86
5 changed files with 64 additions and 3 deletions

View file

@ -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.Map;
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 @@ public class Todo extends AbstractQueue<Env<AttrContext>> {
}
}
/**
* 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;

View file

@ -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 @@ public class JavaCompiler {
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;

View file

@ -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 {
}

View file

@ -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;
}

View file

@ -0,0 +1,4 @@
[attribute Explicit]
[flow Explicit]
[desugar Explicit]
[generate code Explicit]