changeset 3407:f4ea5dca6498

8043253: Slow javac compile times in JDK 8 Summary: Enable on-demand diagnostic source position completion Reviewed-by: jjg, vromero
author mcimadamore
date Wed, 18 Jun 2014 13:51:50 +0100
parents d8d49a41294a
children ca2f625d3712
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 10:44:16 2014 +0200
+++ b/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<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
@@ -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();
     }
 
     /**