RFR: 8355896: Lossy narrowing cast of JVMCINMethodData::size

Boris Ulasevich bulasevich at openjdk.org
Wed Apr 30 19:35:23 UTC 2025


In https://github.com/openjdk/jdk/pull/21276 mutable_data, which includes relocations, metadata, and jvmci_data, was moved to a separately malloc'ed blob. The nmethod (a CodeBlob) holds a pointer to the mutable_data blob and stores its internal offsets.

As part of that change, I reused the former uint16_t offset field to store jvmci_data_size. This turned out to be incorrect, since jvmci_data can exceed 64 KB (as shown in https://github.com/openjdk/jdk/pull/24753).

The most direct fix would be to change jvmci_data_size to uint, placing it alongside other int fields to avoid padding. However, in fact on my build this increases the size of the nmethod structure from 240 to 248 bytes, which I would prefer to avoid.

Instead, I propose storing metadata_size in the existing uint16_t field. The average metadata_size is approximately 140 bytes, and the maximum observed in practice is around 4 KB. While, like oops_size, this value is not formally guaranteed to remain below 64 KB, no cases have been observed where this limit is exceeded. A GUARANTEE check is included to immediately catch any overflow if it ever occurs.

Testing: in progress.

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

Commit messages:
 - 8355896: lossy narrowing cast of JVMCINMethodData::size

Changes: https://git.openjdk.org/jdk/pull/24965/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=24965&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8355896
  Stats: 12 lines in 2 files changed: 4 ins; 0 del; 8 mod
  Patch: https://git.openjdk.org/jdk/pull/24965.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/24965/head:pull/24965

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


More information about the hotspot-compiler-dev mailing list