Use of C++ dynamic global object initialization with thread guards

Florian Weimer fweimer at redhat.com
Tue Dec 5 10:08:38 UTC 2023


* Andrew Haley:

> On 12/4/23 07:28, Florian Weimer wrote:
>> Furthermore, most uses of C++ dynamic initialization involve a
>> computation that is idempotent and have unused bit patterns in the
>> initialized value.  This means that a separate guard variable is not
>> needed, and a simple atomic store/atomic load could be used.
>
> I used it in HotSpot code to trigger one-time resolution of some JDK
> classes. These classes were in an incubator module, so I did not want
> them to be loaded by default. I guess we could replace the
> C++ mechanism by, one of our own, but that doesn't seem to me to be
> much of a maintenance win.

It pulls in a chunk of the C++ run-time, the complete C++ exception
handling implementation is required.  In GCC 12 and later, the C++
unwinder is no longer self-contained, so you pick up a dependency on
glibc 2.35 or later if you link libstdc++ statically.

Thanks,
Florian



More information about the hotspot-dev mailing list