RFR: 8256256: UL should not use heap allocation for output string [v2]

Kim Barrett kim.barrett at oracle.com
Wed Nov 18 13:21:14 UTC 2020


> On Nov 17, 2020, at 11:32 PM, Yumin Qi <minqi at openjdk.java.net> wrote:
> 
>> Hi, Please review
>>  Unified Logging uses 512 bytes buffer on stack for printing out message, above that will allocate heap for extra space needed. This may potentially may cause a circulation when we log the heap allocation and the log message is over 512. The max logging buffer size now is increased to 4096 and above that, output will be truncated.
>> 
>> Tests: tier1,tier4
> 
> Yumin Qi has updated the pull request incrementally with one additional commit since the last revision:
> 
>  Use malloc/free for large log message buffer

A drive-by comment rather than a review.  An approach to this sort of
problem that I've used in the past is something like:

Assuming that logging while logging is fairly rare, and that most threads
don't ever generate "large" log messages.

Thread local free_log_buffer, initially null.

When need a log buffer, first check free_log_buffer.  If non-null, take it,
setting free_log_buffer to null.

If, while using a log buffer, run out of space, allocate a new one, copy,
and free the old one.

When done with a log buffer, first check free_log_buffer.  If it's null,
record the done-with log buffer there.  If it's not null, record the larger
of the existing value and the done-with buffer there and free the other.

So each thread has a local high-water sized log buffer.  This can be layered
on with a relatively small stack buffer that usually gets used, with the
allocated buffer only used when needed.  Most threads never need it.



More information about the hotspot-runtime-dev mailing list