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

David Holmes dholmes at openjdk.java.net
Wed Nov 18 05:22:04 UTC 2020


On Wed, 18 Nov 2020 04:32:18 GMT, Yumin Qi <minqi at openjdk.org> 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

Hi Yumin,

This basic change seems okay, but I'm still somewhat skeptical that this one location is all that needs changing to allow NMT to use UL without the UL code allocating anything tracked by NMT. For example, what if we have to grow the logMessageBuffer?

Thanks,
David

src/hotspot/share/logging/logTagSet.cpp line 129:

> 127:   if ((size_t)ret >= sizeof(buf)) {
> 128:     size_t newbuf_len = prefix_len + ret + 1;
> 129:     char* newbuf = (char*)::calloc(newbuf_len, sizeof(char));

Do we need to zero the array with calloc?
The `(char*)` cast shouldn't be needed.

src/hotspot/share/logging/logTagSet.cpp line 131:

> 129:     char* newbuf = (char*)::calloc(newbuf_len, sizeof(char));
> 130:     if (newbuf == nullptr) {
> 131:       tty->print_cr("Out of memory at logging, allocate " SIZE_FORMAT " bytes", newbuf_len);

Suggestion: " Out of memory during lohging, trying to allocate XXX bytes"

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

PR: https://git.openjdk.java.net/jdk/pull/1246


More information about the hotspot-runtime-dev mailing list