RFR: JDK-8327169: serviceability/dcmd/vm/SystemMapTest.java and SystemDumpMapTest.java may fail after JDK-8326586
Thomas Stuefe
stuefe at openjdk.org
Wed Mar 20 09:26:32 UTC 2024
https://bugs.openjdk.org/browse/JDK-8326586 improved speed of System.map by exploiting the fact that VMA addresses are usually ordered ascending when read from /proc/pid/maps, and keeping track of the index of the last matching NMT region. That was a dramatic speed increase.
However, there is an embarrassing error. The index was kept inside a function-local static variable. But it depends on the number of NMT regions, and after calling System.map once at point-in-time A, it is equal to (number of NMT regions that were alive at A). If we call System.map again, at point-in-time B, and in the meantime mappings were released and we have fewer NMT regions, the stored index refers to an invalid position (larger than NMT region array count).
This messes up the next System.map printing. It can also theoretically cause a crash, since we dereference that out-of-bounds index, but I was not able to reproduce (the referenced array is usually over-allocated). Since we use the wrong - too high - index, we never enter the printing loop inside `CachedNMTInformation::lookup`, so we never print NMT regions. This makes the tests fail.
Tests: I was able to intermittendly reproduce the error without the patch by running a JVM and simulating NMT region cleanup between two calls to System.map. With this patch, the error is gone.
--
The obvious solution is to not use function-scope statics, but to store the last used index in a member inside CachedNMTInformation, and thus give it the same lifetime as that cache.
-------------
Commit messages:
- revert _last setting
- JDK-8327169-serviceability-dcmd-vm-SystemMapTest-java-and-SystemDumpMapTest-java-fails-after-JDK-8326586
Changes: https://git.openjdk.org/jdk/pull/18392/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=18392&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8327169
Stats: 9 lines in 1 file changed: 3 ins; 1 del; 5 mod
Patch: https://git.openjdk.org/jdk/pull/18392.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/18392/head:pull/18392
PR: https://git.openjdk.org/jdk/pull/18392
More information about the hotspot-runtime-dev
mailing list