RFR: 8267952: async logging supports to dynamically change tags and decorators

Xin Liu xliu at openjdk.java.net
Wed Jun 9 07:16:15 UTC 2021


On Wed, 9 Jun 2021 04:41:24 GMT, David Holmes <dholmes at openjdk.org> wrote:

>> Support dynamic reconfiguration for async logging. 2 unittests are provided.
>> The regression test discovers a race condition in LogTagSet::log() even with
>> synchronous logging. It's not MT-safe if context switch happens between the
>> creation of LogDecorations  and LogOutputList::Iterator. fixed.
>
> src/hotspot/share/logging/logConfiguration.cpp line 268:
> 
>> 266:   //
>> 267:   // LogDecorator is a set of decorators represented in a uint. sizeof(uint) is not greater than a machine word,
>> 268:   // so store of it is atomic on the mainstream processors. I.e. readers see either its older value or new value.
> 
> This is not necessarily true - the field also has to have correct alignment to ensure atomic accesses. The convention we are adopting is that all racily accessed fields like _decorators should be declared volatile, and accessed using Atomic::load and Atomic::store.

To support machines without unaligned memory access, C++ defines "alignment requirement" for class and struct. 
Not only sizeof(LogDecorators) == sizeof(uint) == 4, C++ can also guarantee that alignof(logDecorators) is 4. 
Therefore, it's impossible that to unaligned access for its field _decorators. 


class LogDecorators {
  uint _decorators;
};


Therefore, I think the current code which use normal assignment is atomic. Of course, using Atomic::store manifests it's an atomic store. I will try to use Atomic::store().

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

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


More information about the hotspot-runtime-dev mailing list