RFR: 8263185: Mallinfo deprecated in glibc 2.33

Thomas Stuefe stuefe at openjdk.java.net
Fri Mar 12 14:42:09 UTC 2021


On Fri, 12 Mar 2021 10:12:17 GMT, Christoph Göttschkes <cgo at openjdk.org> wrote:

> Starting with glibc 2.33, mallinfo is deprecated in favor of the new mallinfo2 API. Both APIs work the same way, the only difference is, that mallinfo2 uses size_t instead of int for the fields of the struct, containing the information about malloc. Please see the [glibc release notes](https://sourceware.org/pipermail/libc-alpha/2021-February/122207.html).
> 
> Testing with tier1 on a system with glibc 2.33 and on a system with glibc 2.31.

Hi Chris,

are you sure this is true? That we are unable to run on machines with older glibcs than the build machine uses? This is new to me. 

If this is not true, I would dynamically resolve mallinfo2. This is too unimportant a functionality to introduce a hard glibc dependency.

Minor remarks inline.

..Thomas

src/hotspot/os/linux/os_linux.cpp line 2235:

> 2233:   struct mallinfo2 mi = ::mallinfo2();
> 2234:   const size_t total_allocated = mi.uordblks;
> 2235:   const bool might_have_wrapped = false;

Can you move declaration of might_have_wrapped - defaulted to false - outside the define? Same for total_allocated.

src/hotspot/os/linux/os_linux.cpp line 2241:

> 2239:   // So values may have wrapped around. Still useful enough to see how much glibc thinks
> 2240:   // we allocated.
> 2241:   const size_t total_allocated = static_cast<size_t>(mi.uordblks);

The original version was correct here, please restore it. You need to make the int value unsigned before extending it to 64bit size_t, otherwise you get sign extension for values >= 2g. 

One could argue that the second cast to size_t in the original coding was superfluous, but the cast to unsigned was needed.

src/hotspot/os/linux/os_linux.cpp line 2245:

> 2243:   const bool might_have_wrapped = (vmrss * K) > UINT_MAX && (vmrss * K) > (total_allocated + UINT_MAX);
> 2244: #endif // __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 33)
> 2245:   st->print("C-Heap outstanding allocations: " SIZE_FORMAT "K", total_allocated / K);

Shorten this to:
st->print("C-Heap outstanding allocations: " SIZE_FORMAT "K%s",
           total_allocated / K, wrapped ? " (possibly wrapped)" : "");
?

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

Changes requested by stuefe (Reviewer).

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


More information about the hotspot-runtime-dev mailing list