RFR: 8325945: Error reporting should limit the number of String characters printed [v4]

Thomas Stuefe stuefe at openjdk.org
Thu Jul 18 07:28:35 UTC 2024


On Thu, 18 Jul 2024 06:52:44 GMT, David Holmes <dholmes at openjdk.org> wrote:

>> Please review this enhancement that intends to improve the readability of error logs when very long `java.lang.String`s exist and when printed in full they obscure things in the log.
>> 
>> The suggestion was to add a `MaxStringPrintSize` flag, similar to the `MaxElementPrintSize` for arrays. I've set the default to 256 (arbitrary selection: not too big, not too small - may need adjusting) with a range from 2 to O_BUFLEN.
>> 
>> The method `java_lang_String::print` now takes a `max_length` parameter that defaults to `MaxStringPrintSize`. This allows more direct control if specific call sites want to print full strings regardless.
>> 
>> If a string's length exceeds `max_length` then we print it as follows:
>> 
>> "< first max_length/2 characters> ... <last max_length/2 characters>" (abridged)
>> 
>> For example if we print "ABCDE" with a max_length of 4 then the output is literally:
>> 
>> "AB ... DE" (abridged)
>> 
>> The message doesn't mention `MaxPrintStringSize` as that may not be involved in limiting the printed length. Developers will need to know to look at that (which is not 100% satisfactory but explaining everything in the output itself seems a bit excessive).
>> 
>> For testing purposes I added a WhiteBox API to print the string to a `stringStream` and then return it as a new `java.lang.String`.
>> 
>> Testing:
>>  - new test added for validation purposes
>>  - tiers 1 - 3 as sanity testing
>> 
>> Thanks
>
> David Holmes has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Update comment

src/hotspot/share/classfile/javaClasses.cpp line 799:

> 797:   if (length > max_length) {
> 798:     st->print(" (abridged) ");
> 799:   }

Do we still need this marker?

src/hotspot/share/runtime/globals.hpp line 1312:

> 1310:           "printed with the middle of the string elided.")                  \
> 1311:           range(2, O_BUFLEN)                                                \
> 1312:                                                                             \

This would make sense as a product diagnostic switch. You want to be able to increase this at a customer if needed.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/20150#discussion_r1682332121
PR Review Comment: https://git.openjdk.org/jdk/pull/20150#discussion_r1682334543


More information about the hotspot-dev mailing list