RFR: 8331626: unsafe.cpp:162:38: runtime error in index_oop_from_field_offset_long - applying non-zero offset 4563897424 to null pointer
Stefan Karlsson
stefank at openjdk.org
Mon May 6 08:35:55 UTC 2024
On Fri, 3 May 2024 14:01:34 GMT, Martin Doerr <mdoerr at openjdk.org> wrote:
> `index_oop_from_field_offset_long` is sometimes used to access an absolute address by using `p == nullptr`. Unfortunately, `nullptr + byte_offset` implies undefined behavior and should better get fixed. UBSan complains about it (see JBS issue).
> A possible solution is to replace pointer arithmetic by integer arithmetic. We can use unsigned because `assert_field_offset_sane` checks that `byte_offset >= 0`.
Changes requested by stefank (Reviewer).
src/hotspot/share/prims/unsafe.cpp line 158:
> 156: assert_field_offset_sane(p, field_offset);
> 157: uintptr_t base_address = cast_from_oop<uintptr_t>(p),
> 158: byte_offset = (uintptr_t)field_offset_to_byte_offset(field_offset);
We tend to not use this style for setting up variables in HotSpot code: I propose that you update the code to:
Suggestion:
uintptr_t base_address = cast_from_oop<uintptr_t>(p);
uintptr_t byte_offset = (uintptr_t)field_offset_to_byte_offset(field_offset);
-------------
PR Review: https://git.openjdk.org/jdk/pull/19087#pullrequestreview-2040261999
PR Review Comment: https://git.openjdk.org/jdk/pull/19087#discussion_r1590699897
More information about the hotspot-dev
mailing list