# HG changeset patch # User mcimadamore # Date 1403095910 -3600 # Node ID 64c8d860c984d14064c4fd40dc2853f56cbfda66 # Parent 55c823e853f22760a135184be76638da3443e09b 8043253: Slow javac compile times in JDK 8 Summary: Enable on-demand diagnostic source position completion Reviewed-by: jjg, vromero diff -r 55c823e853f2 -r 64c8d860c984 langtools/src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java --- a/langtools/src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java Wed Jun 18 10:44:16 2014 +0200 +++ b/langtools/src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java Wed Jun 18 13:51:50 2014 +0100 @@ -354,13 +354,41 @@ private final DiagnosticType type; private final DiagnosticSource source; private final DiagnosticPosition position; - private final int line; - private final int column; private final String key; protected final Object[] args; private final Set flags; private final LintCategory lintCategory; + /** source line position (set lazily) */ + private SourcePosition sourcePosition; + + /** + * This class is used to defer the line/column position fetch logic after diagnostic construction. + */ + class SourcePosition { + + private final int line; + private final int column; + + SourcePosition() { + int n = (position == null ? Position.NOPOS : position.getPreferredPosition()); + if (n == Position.NOPOS || source == null) + line = column = -1; + else { + line = source.getLineNumber(n); + column = source.getColumnNumber(n, true); + } + } + + public int getLineNumber() { + return line; + } + + public int getColumnNumber() { + return column; + } + } + /** * Create a diagnostic object. * @param formatter the formatter to use for the diagnostic @@ -390,14 +418,6 @@ this.position = pos; this.key = key; this.args = args; - - int n = (pos == null ? Position.NOPOS : pos.getPreferredPosition()); - if (n == Position.NOPOS || source == null) - line = column = -1; - else { - line = source.getLineNumber(n); - column = source.getColumnNumber(n, true); - } } /** @@ -494,7 +514,10 @@ * @return the line number within the source referred to by this diagnostic */ public long getLineNumber() { - return line; + if (sourcePosition == null) { + sourcePosition = new SourcePosition(); + } + return sourcePosition.getLineNumber(); } /** @@ -502,7 +525,10 @@ * @return the column number within the line of source referred to by this diagnostic */ public long getColumnNumber() { - return column; + if (sourcePosition == null) { + sourcePosition = new SourcePosition(); + } + return sourcePosition.getColumnNumber(); } /**