RFR: 8292989: Avoid dynamic memory in AsyncLogWriter [v4]

Xin Liu xliu at openjdk.org
Fri Sep 9 22:26:53 UTC 2022


On Thu, 8 Sep 2022 10:55:48 GMT, Thomas Stuefe <stuefe at openjdk.org> wrote:

>> Xin Liu has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   fix MSVC warning C4267
>>   
>>   MSVC reports logAsyncWriter.cpp(62): warning C4267: 'initializing': conversion from
>>   'size_t' to 'int', possible loss of data
>
> src/hotspot/share/logging/logAsyncWriter.cpp line 64:
> 
>> 62:   size_t sz = align_up(sizeof(Message) + len, sizeof(void*));
>> 63: 
>> 64:   if (_pos + sz <= _capacity || output == nullptr/*token*/) {
> 
> I don't understand this. The push token thing is not zero-sized, so what happens if we go over capacity? Or, in other words, if we fill the buffer with push tokens only, won't we overwrite and crash?

Currently, there's only one token, ie. the flushing token. We use it to implement "flushing" semantic. 

`AsyncLogWriter::flush` inserts it and is blocked until "flushing" is complete. 
Therefore, one queue can only have one token anytime. I reserve it in ctor so enqueuing of the token always succeeds. Unlike regular enqueuing, failure is not acceptable because it will hang AsyncLogWriter thread. 

Previously, I have an object called 'Token'. Since now the constructor only works for in-place new, I can't construct it on on c-heap or stack, so I use a tuple {nullptr,  AsyncLogWriter::None, ""} here.


void AsyncLogWriter::Buffer::push_flush_token() {
  bool result = push_back(nullptr, AsyncLogWriter::None, "");
  assert(result, "fail to enqueue the flush token");
}

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

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


More information about the hotspot-runtime-dev mailing list