changeset 2448:829f01e7f732

8043253: Slow javac compile times in JDK 8 Summary: Enable on-demand diagnostic source position completion Reviewed-by: jjg, vromero
author mcimadamore
date Thu, 19 Jun 2014 12:22:39 +0100
parents 76b61848c9a4
children a3ad6e2ede44 c51ac16f339f
files src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java
diffstat 1 files changed, 38 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java	Wed Jun 18 12:06:50 2014 -0400
+++ b/src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java	Thu Jun 19 12:22:39 2014 +0100
@@ -355,13 +355,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<DiagnosticFlag> 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
@@ -391,14 +419,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);
-        }
     }
 
     /**
@@ -495,7 +515,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();
     }
 
     /**
@@ -503,7 +526,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();
     }
 
     /**