RFR: 8332237: [nmt] Remove the need for ThreadStackTracker::track_as_vm()
Afshin Zafari
azafari at openjdk.org
Thu May 16 12:33:01 UTC 2024
On Tue, 14 May 2024 14:51:00 GMT, Thomas Stuefe <stuefe at openjdk.org> wrote:
> 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.
Nice cleanup. All OK. Thanks.
-------------
Marked as reviewed by azafari (Committer).
PR Review: https://git.openjdk.org/jdk/pull/19231#pullrequestreview-2060603207
More information about the hotspot-runtime-dev
mailing list