RFR: 8286876: NMT.test_unaliged_block_address_vm_assert fails if using clang toolchain [v2]

Johan Sjölen jsjolen at openjdk.org
Mon Dec 5 13:16:37 UTC 2022


> This fixes a bug by removing some UB which Clang used in order to make a test fail. Specifically, Clang optimized the `is_aligned` call in ` MallocHeader::assert_block_integrity` to `true`, because an unaligned `this` is  UB. This is fixed by making a static method, essentially. The new code liberally uses `reinterpret_cast<uintptr_t>()`, this is a specifically mentioned as legal use on https://en.cppreference.com/w/cpp/language/reinterpret_cast .
> 
> **The idea is essentially:** Make sure the pointer looks OK before casting it to a `MallocHeader*`.
> 
> I also changed the definition of `malloc_header`:
> 
> ```c++
> // old
>     return (MallocHeader*)((char*)memblock - sizeof(MallocHeader));
> // new
>     return &(((MallocHeader*)memblock)[-1]);
> 
> 
> The previous definition was UB, because you shouldn't cast from a pointer with smaller alignment to one with larger alignment requirements.
> 
> I also made `MallocHeader::print_block_on_error` static, as the `this` argument was always equal to the `bad_address`.

Johan Sjölen has updated the pull request incrementally with one additional commit since the last revision:

  Generate assert_block_integrity thru templated function

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/11465/files
  - new: https://git.openjdk.org/jdk/pull/11465/files/a4457d8a..1fc22a32

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=11465&range=01
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=11465&range=00-01

  Stats: 16 lines in 3 files changed: 11 ins; 0 del; 5 mod
  Patch: https://git.openjdk.org/jdk/pull/11465.diff
  Fetch: git fetch https://git.openjdk.org/jdk pull/11465/head:pull/11465

PR: https://git.openjdk.org/jdk/pull/11465


More information about the hotspot-runtime-dev mailing list