RFR: 8303078: Reduce allocations when pretty printing JCTree during compilation [v3]

Jonathan Gibbons jjg at openjdk.org
Wed Feb 22 22:16:11 UTC 2023


On Wed, 22 Feb 2023 21:39:32 GMT, Christoph Dreis <duke at openjdk.org> wrote:

>> src/jdk.compiler/share/classes/com/sun/tools/javac/tree/DocPretty.java line 82:
>> 
>>> 80:      */
>>> 81:     private void print(char c) throws IOException {
>>> 82:         out.write(c);
>> 
>> The restriction to skip calling `Convert.escapeUnicode(s.toString())` leaks into `print(List, char sep)`.
>> 
>> If we wanted to be paranoid we could do one or more of the following;
>> 
>> 1. Change the body of this method to something like<br> `if (Character.isASCII(c)) out.write(c); else print((Character) c);`
>> 2. include an `assert` or call to a method in `Assert.*` to verify the argument is ASCII.
>> 3. change that `protected void print(List, char)` method to be `private` instead of `protected`
>> 
>> I guess I'd not bother with 1 or 2, but maybe go with 3, since it has no effect on performance, and better restricts the functionality to just this class.   I note there are no discernable external usages of this method.
>
> Already asked above: should we really be paranoid here? There is a big class comment above that anyone depending on the internal api uses this at his own risk...
> But if I should change anything I'd rather make the method `private`

_(Sorry for the duplicate entry)_

I think making the method `private` is good enough, and doing it in the same changeset that changes the signature is even better for future code historians.

-------------

PR: https://git.openjdk.org/jdk/pull/12667


More information about the compiler-dev mailing list