--- old/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Enter.java 2015-02-23 20:10:45.000000000 +0100 +++ new/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Enter.java 2015-02-23 20:10:45.000000000 +0100 @@ -25,7 +25,6 @@ package com.sun.tools.javac.comp; -import java.util.*; import javax.tools.JavaFileObject; import javax.tools.JavaFileManager; @@ -34,7 +33,6 @@ import com.sun.tools.javac.code.Scope.*; import com.sun.tools.javac.code.Symbol.*; import com.sun.tools.javac.code.Type.*; -import com.sun.tools.javac.jvm.*; import com.sun.tools.javac.main.Option.PkgInfo; import com.sun.tools.javac.tree.*; import com.sun.tools.javac.tree.JCTree.*; @@ -87,11 +85,11 @@ public class Enter extends JCTree.Visitor { protected static final Context.Key enterKey = new Context.Key<>(); + Annotate annotate; Log log; Symtab syms; Check chk; TreeMaker make; - Annotate annotate; TypeEnter typeEnter; Types types; Lint lint; @@ -102,6 +100,30 @@ private final Todo todo; + /** Semaphore to delay annotations while entering */ + private int enterCount = 0; + + /** Called when the Enter phase starts. */ + public void enterStart() { + enterCount++; + } + + /** Called after the Enter phase completes. */ + public void enterDone() { + enterCount--; + if (enterCount == 0) + annotate.flush(); + } + + /** Variant which allows for a delayed flush of annotations. + * Needed by ClassReader */ + public void enterDoneWithoutFlush() { + enterCount--; + } + + /** are we entering? */ + public boolean isEntering() {return enterCount > 0; } + public static Enter instance(Context context) { Enter instance = context.get(enterKey); if (instance == null) @@ -252,11 +274,13 @@ Env prevEnv = this.env; try { this.env = env; + enterStart(); tree.accept(this); return result; } catch (CompletionFailure ex) { return chk.completionError(tree.pos(), ex); } finally { + enterDone(); this.env = prevEnv; } } @@ -473,7 +497,7 @@ * @param c The class symbol to be processed or null to process all. */ public void complete(List trees, ClassSymbol c) { - annotate.enterStart(); + enterStart(); ListBuffer prevUncompleted = uncompleted; if (typeEnter.completionEnabled) uncompleted = new ListBuffer<>(); @@ -494,9 +518,9 @@ typeEnter.ensureImportsChecked(trees); } + enterDone(); } finally { uncompleted = prevUncompleted; - annotate.enterDone(); } }