RFR: 8301404: Replace os::malloc with os::realloc, so we only have 1 code path

Gerard Ziemski gziemski at openjdk.org
Tue Mar 18 18:18:51 UTC 2025


This is the 2nd time I am proposing this (controversial?) change, but this time I do have performance numbers, which indicate no change in speed (using NMTBenchmark from https://github.com/openjdk/jdk/pull/23786):

proposed:


time:72,642,827[ns]
[samples:807,804] [NMT headers:382,064]
[malloc#:588,703] [realloc#:12,462] [free#:206,639]
memory requested:57,274,288 bytes, allocated:69,004,800 bytes
malloc overhead:4,853,360 bytes [8.47%], NMT headers overhead:6,877,152 bytes [12.01%]


existing code:


time:73,085,446[ns]
[samples:807,804] [NMT headers:382,064]
[malloc#:588,703] [realloc#:12,462] [free#:206,639]
memory requested:57,274,288 bytes, allocated:69,004,800 bytes
malloc overhead:4,853,360 bytes [8.47%], NMT headers overhead:6,877,152 bytes [12.01%]


Note: the NMTBenchmark reports `realloc(nullptr)` as `mallocs()`, which is why both versions show the same count for `mallocs/reallocs`.

The performance is virtually the same where I sampled each test 30 times and took the best (the shortest).

This proposed change factors out the common code and simplifies both os::malloc and os::realloc. We were able to reduce malloc from 44 lines down to 8 (saving of 36 lines) and realloc from 84 to 55 (29 lines).

To me the most important part here is that we reduce the number of times that NMT has to interact with the native allocation code.

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

Commit messages:
 - revert pre-init cache
 - check for NMT, rename offset to chunk
 - fix memset
 - fix memset
 - fix memset
 - cleanup
 - factor out common malloc/realloc code
 - fix build
 - fix build
 - fix build
 - ... and 2 more: https://git.openjdk.org/jdk/compare/da2b4f07...cec25b45

Changes: https://git.openjdk.org/jdk/pull/23994/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=23994&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8301404
  Stats: 112 lines in 2 files changed: 28 ins; 43 del; 41 mod
  Patch: https://git.openjdk.org/jdk/pull/23994.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/23994/head:pull/23994

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


More information about the hotspot-runtime-dev mailing list