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

Vladimir Kozlov kvn at openjdk.org
Wed Apr 30 19:50:44 UTC 2025


On Wed, 30 Apr 2025 13:10:19 GMT, Boris Ulasevich <bulasevich at openjdk.org> wrote:

> 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.

Let me test it.

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

PR Review: https://git.openjdk.org/jdk/pull/24965#pullrequestreview-2808241843


More information about the hotspot-compiler-dev mailing list