From 2060c8ea14119048f06b5a8c3c251f4e8d1ef43b Mon Sep 17 00:00:00 2001 From: Jim Laskey Date: Thu, 13 Apr 2023 11:42:00 +0000 Subject: [PATCH] 8305688: jdk build --with-memory-size=1024 broken by JDK-8305100 Reviewed-by: martin --- .../tools/javac/parser/JavadocTokenizer.java | 11 +++++++- .../sun/tools/javac/parser/UnicodeReader.java | 28 +++++++++++-------- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavadocTokenizer.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavadocTokenizer.java index 4cd0e1c2fcd..3d01e45f9b2 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavadocTokenizer.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavadocTokenizer.java @@ -96,7 +96,7 @@ public class JavadocTokenizer extends JavaTokenizer { /** * StringBuilder used to extract the relevant portion of the Javadoc comment. */ - private final StringBuilder sb; + private StringBuilder sb; /** * Indicates if newline is required. @@ -166,6 +166,8 @@ public class JavadocTokenizer extends JavaTokenizer { super.scanDocComment(); } finally { docComment = sb.toString(); + sb = null; + offsetMap.trim(); } } } @@ -310,6 +312,13 @@ public class JavadocTokenizer extends JavaTokenizer { } } + /** + * Reduce map to minimum size. + */ + void trim() { + map = Arrays.copyOf(map, size); + } + /** * Binary search to find the entry for which the string index is less * than pos. Since the map is a list of pairs of integers we must make diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/UnicodeReader.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/UnicodeReader.java index 62a0b224927..3af23f50250 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/UnicodeReader.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/UnicodeReader.java @@ -54,6 +54,11 @@ public class UnicodeReader { */ private final int length; + /** + * Virtual position offset in the original buffer. + */ + private final int offset; + /** * Character buffer index of character currently being observed. */ @@ -115,7 +120,7 @@ public class UnicodeReader { * @param length length of meaningful content in buffer. */ protected UnicodeReader(Log log, char[] array, int length) { - this(log, array, 0, length); + this(log, array, 0, 0, length); } /** @@ -127,9 +132,10 @@ public class UnicodeReader { * @param endPos end of meaningful content in buffer. */ @SuppressWarnings("this-escape") - protected UnicodeReader(Log log, char[] array, int pos, int endPos) { + protected UnicodeReader(Log log, char[] array, int offset, int pos, int endPos) { this.buffer = array; this.length = endPos; + this.offset = offset; this.position = pos; this.width = 0; this.character = '\0'; @@ -315,22 +321,22 @@ public class UnicodeReader { } /** - * Return the current position in the character buffer. + * Return the virtual position in the character buffer. * - * @return current position in the character buffer. + * @return virtual position in the character buffer. */ protected int position() { - return position; + return offset + position; } /** - * Reset the reader to the specified position. + * Reset the reader to the specified virtual position. * Warning: Do not use when previous character was an ASCII or unicode backslash. * @param pos */ protected void reset(int pos) { - position = pos; + position = pos - offset; width = 0; wasBackslash = false; wasUnicodeEscape = false; @@ -474,7 +480,7 @@ public class UnicodeReader { int endPos = position; accept('\r'); accept('\n'); - return lineReader(pos, endPos); + return new UnicodeReader(log, buffer, offset, pos, endPos); } /** @@ -487,7 +493,7 @@ public class UnicodeReader { * @return a new reader */ protected UnicodeReader lineReader(int pos, int endPos) { - return new UnicodeReader(log, buffer, pos, endPos); + return new UnicodeReader(log, buffer, offset, pos - offset, endPos - offset); } /** @@ -561,7 +567,7 @@ public class UnicodeReader { } // Be prepared to retreat if not a match. - int savedPosition = position; + int savedPosition = position(); nextCodePoint(); @@ -695,7 +701,7 @@ public class UnicodeReader { * @param endPos end of meaningful content in buffer. */ protected PositionTrackingReader(UnicodeReader reader, int pos, int endPos) { - super(reader.log, reader.buffer, pos, endPos); + super(reader.log, reader.getRawCharacters(pos, endPos), reader.offset + pos, 0, endPos - pos); this.column = 0; }