RFR: 8351334: [ubsan] memoryReserver.cpp:552:60: runtime error: applying non-zero offset 1073741824 to null pointer [v5]

Axel Boldt-Christmas aboldtch at openjdk.org
Thu Sep 18 15:37:38 UTC 2025


On Thu, 18 Sep 2025 07:44:04 GMT, Afshin Zafari <azafari at openjdk.org> wrote:

> I followed (IIUC) your comments on replacing uintptr_t and uint64_t because of differences in platforms.

Sorry, something must be lacking in my communication. 

What I was trying to describe was that you will have issues if you expect the two typedefs to have the same underlying type even if we can assume they are both 64bit and unsigned.  You currently have the same issue with `size_t` and `uintptr_t`. 

The issue is that you are using a template function which expects something along the lines of `T MAX2(T, T)`. But you are using it with two distinct (but compatible) types. The compiler cannot infer if you want `unsigned long long MAX2(unsigned long long, unsigned long long)` or `unsigned long MAX2(unsigned long, unsigned long)` so you need to tell it. There are in general two ways to do this. Either you cast:
```C++
  lowest_start = MAX2(lowest_start, (uintptr_t)(UnscaledOopHeapMax - size));

or you select the specific instantiation of the templated function:
```C++
  lowest_start = MAX2<uintptr_t>(lowest_start, UnscaledOopHeapMax - size);

I prefer the later as it allows `-Wconversions` to warn if these types are incompatible(/lossy). While the cast will silence such warnings. If I see the former I usually assume that we are truncating or allow truncation.

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

PR Comment: https://git.openjdk.org/jdk/pull/26955#issuecomment-3308161319


More information about the hotspot-gc-dev mailing list