RFR: JDK-8283674: Pad ObjectMonitor allocation size to cache line size

Kim Barrett kbarrett at openjdk.java.net
Tue Mar 29 21:22:48 UTC 2022


On Mon, 28 Mar 2022 13:22:30 GMT, Thomas Stuefe <stuefe at openjdk.org> wrote:

> > Note that the padding only avoids that the same fields of different ObjectMonitors can end up on the same cache line. The beginning of the next one can still fall into the same cache line as the end of the previous one. We'd need alignment to fix that.
> 
> Oh, you are right, good catch. We'd need posix_memalign. We don't have an abstraction for that in os. The alternative would be the typical solution of malloc'ing size * 2 and then aligning up. Sigh, what a nuisance.

C++11 has `alignas` and friends (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2341.pdf), which included the concept of _over-aligned types_.  Unfortunately, they forgot alignment of the memory obtained by `new` expressions for over-aligned types.  That wasn't fixed until C++17 (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0035r4.html - Dynamic memory allocation for over-aligned data).

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

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


More information about the hotspot-runtime-dev mailing list