RFR: 8292989: Avoid dynamic memory in AsyncLogWriter [v2]
Thomas Stuefe
stuefe at openjdk.org
Tue Sep 6 16:33:08 UTC 2022
On Tue, 6 Sep 2022 16:11:40 GMT, Thomas Stuefe <stuefe at openjdk.org> wrote:
>> Xin Liu has updated the pull request incrementally with one additional commit since the last revision:
>>
>> update according to feedbacks.
>
> src/hotspot/share/logging/logAsyncWriter.cpp line 75:
>
>> 73: p->set_message(dest);
>> 74: _pos += sz;
>> 75: return true;
>
> That's pretty hacky... :-) And `set_message` only exists because you need to repair the message pointer here, right?
>
> Proposal:
>
> Make AsyncLogMessage self-contained and variable-sized by letting the message follow the header. Like this:
>
>
> class AsyncLogMessage {
> LogFileStreamOutput* _output;
> const LogDecorations _decorations;
> const size_t _len; // optional, or could also be 32- maybe even 16 bit
> public:
> size_t len_in_bytes() const { return align_up(sizeof(AsyncLogMessage) + _len); }
> const char* message() { return (const char*) (this + 1); }
> };
>
>
> Then give it a placement new() and place it inside the Buffer right away instead of creating it on the stack and then copying it to the buffer. Just an idea.
Update: I looked at AsyncLogMessage and you are almost at what I propose anyway since the in-buffer version of AsyncLogMessage already follows my proposed layout. And your `AsyncLogMessage::size()` is similar to what I propose too.
But the way you do it, you have two versions, one where the message follows the header, one where it is wherever. This means that `AsyncLogMessage::size()` is wrong for at least half the time.
-------------
PR: https://git.openjdk.org/jdk/pull/10092
More information about the hotspot-runtime-dev
mailing list