JDK-8275207 : Enabling of native memory tracking using NMT_LEVEL causes to JVM crash
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 8
  • Priority: P4
  • Status: In Progress
  • Resolution: Unresolved
  • Submitted: 2021-10-13
  • Updated: 2021-10-18
Related Reports
Relates :  
Description
When trying to enable Java NMT through the `JAVA_TOOL_OPTIONS` env variable, the JVM crashes.

Steps to reproduce:

export JAVA_TOOL_OPTIONS="-XX:+UnlockDiagnosticVMOptions -XX:NativeMemoryTracking=summary -XX:+PrintNMTStatistics"

export NMT_LEVEL_<java process pid>=summary`

And then java will crash:

root@7156fa1d0779:/# export NMT_LEVEL_3326=summary
root@7156fa1d0779:/# ./jdk8u302-b08/bin/java -version
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007fdd2312ab77, pid=3326, tid=0x00007fdd2247d700
#
# JRE version:  (8.0_302-b08) (build )
# Java VM: OpenJDK 64-Bit Server VM (25.302-b08 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# V  [libjvm.so+0xb29b77]  VirtualMemoryTracker::add_reserved_region(unsigned char*, unsigned long, NativeCallStack const&, MemoryType, bool)+0x77
#
# Core dump written. Default location: //core or core.3326
#
# An error report file with more information is saved as:
# //hs_err_pid3326.log
#
# If you would like to submit a bug report, please visit:
#   https://github.com/adoptium/adoptium-support/issues
#
Aborted (core dumped)

Can be easily reproduced in container env, to get java PID - ps gives us current PID, the expected PID will be the next number.

Reproducible on Linux and MacOS.
Comments
Tentative patch is attached.
18-10-2021