RFR: 8356233: NMT: tty->print_cr should not be used in VirtualMemoryTracker::add_reserved_region()

Johan Sjölen jsjolen at openjdk.org
Tue May 20 07:02:53 UTC 2025


On Mon, 19 May 2025 20:11:09 GMT, Gerard Ziemski <gziemski at openjdk.org> wrote:

> To help with debugging NMT we added more info when an assert gets triggered, but we used `tty`, which is involved with locks and unfortunately it triggered:
> 
> 
> # Internal Error (.../open/src/hotspot/share/runtime/mutex.cpp:457), pid=1088443, tid=1088520
> # assert(false) failed: Attempting to acquire lock tty_lock/tty out of order with lock NmtVirtualMemory_lock/service-4 -- possible deadlock
> 
> 
> We avoid this, by printing using `UL` instead of using `tty` directly.

Marked as reviewed by jsjolen (Reviewer).

src/hotspot/share/nmt/virtualMemoryTracker.cpp line 404:

> 402:       }
> 403: 
> 404:       // Print some more details. Don't use UL here to avoid circularities.

It seems unlikely that any circularities would occur, as UL doesn't use the VMT.

src/hotspot/share/nmt/virtualMemoryTracker.cpp line 411:

> 409:                     "       new region: [" INTPTR_FORMAT "-" INTPTR_FORMAT "), memory tag %s.",
> 410:                     p2i(reserved_rgn->base()), p2i(reserved_rgn->end()), NMTUtil::tag_to_name(mem_tag_old),
> 411:                     p2i(base_addr), p2i(base_addr + size), NMTUtil::tag_to_name(mem_tag_new));

This change also now prints the name instead of the index. If you do print the name, then you don't need to use `index_to_tag` as they already are `MemTag`s.

src/hotspot/share/nmt/virtualMemoryTracker.cpp line 419:

> 417:       }
> 418:       const char* msg = ss.as_string(true /* on C-heap */);
> 419:       log_debug(nmt)("%s", msg);

You can just do `log_debug(nmt)("%s", ss.freeze());` and skip the `as_string()`.

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

PR Review: https://git.openjdk.org/jdk/pull/25308#pullrequestreview-2852901488
PR Review Comment: https://git.openjdk.org/jdk/pull/25308#discussion_r2097127250
PR Review Comment: https://git.openjdk.org/jdk/pull/25308#discussion_r2097133382
PR Review Comment: https://git.openjdk.org/jdk/pull/25308#discussion_r2097128142


More information about the hotspot-runtime-dev mailing list