RFR: 8332237: [nmt] Remove the need for ThreadStackTracker::track_as_vm()

Thomas Stuefe stuefe at openjdk.org
Thu May 16 10:48:12 UTC 2024


This PR simplifies NMT by removing a bunch of code needed only to track thread stacks on AIX (`ThreadStackTracker::track_as_vm()` is actually `#ifndef AIX` in disguise).

NMT has two ways to track thread stacks:
A) piggybacking on the virtual memory accounting
B) piggybacking on malloc accounting

(A) is done on all platforms except AIX. (B) is AIX.

This is because on AIX, thread stacks (more precisely, the boundaries of thread stacks as the JVM knows them) are not page-aligned. Therefore we track these stacks as if they had been allocated with malloc. This special handling adds a lot of complex coding to NMT.

We (@zhengyu123 and me) originally decided on this approach to keep NMT versatile and able to deal with platforms that place thread stacks wherever. Or with the hypothetical that the JVM manages its own thread stacks. The latter never manifested - for a number of reasons, the thread library tends to be better at managing thread stacks than the application.

In practice, we only ever did this for AIX. The irony is that with this method, we track stacks as if they were fully alive. So, arguably, this method is just a rather complicated way of iterating all live threads and adding up their thread stack sizes.

On all other platforms, we track thread stacks as virtual memory. For every thread stack tracked, we also query memory liveness via `os::committed_in_range` (on closer inspection, another misnomer since this function does not query commit state but liveness). `os::committed_in_range` is implemented on Linux and Windows, and a fallback variant exists that just acts as if the whole range were committed.

Solving the thread-stacks-not-page-aligned problem can be done in a much simpler way by aligning thread stack boundaries - for the purpose of NMT - inward to the next inner page boundaries. We pay a very small loss in fidelity. But we can now use the same method all other platforms use. We can throw away a bunch of code. And, if we ever implement `os::committed_in_range` for AIX, we get real thread stack liveness tracking for free.

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

Commit messages:
 - Update memTracker.cpp
 - Update virtualMemoryTracker.cpp
 - Update nmtUsage.cpp
 - Update memBaseline.cpp
 - start

Changes: https://git.openjdk.org/jdk/pull/19231/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=19231&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8332237
  Stats: 195 lines in 7 files changed: 10 ins; 137 del; 48 mod
  Patch: https://git.openjdk.org/jdk/pull/19231.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/19231/head:pull/19231

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


More information about the hotspot-runtime-dev mailing list