RFR: 8343531: Improve print_location for invalid heap pointers
Volker Simonis
simonis at openjdk.org
Mon Nov 4 15:10:28 UTC 2024
On Mon, 4 Nov 2024 11:22:47 GMT, Albert Mingkun Yang <ayang at openjdk.org> wrote:
> > but I think it is not trivial.
>
> I was thinking copying the Serial impl into `ParallelScavengeHeap::block_start`; nothing sophisticated.
>
Unfortunately, the Serial implementation doesn't really work reliably if running with `-XX:+UseTLAB` (which is the default). If called with a pointer which points into unallocated TLAB buffer, `ContiguousSpace::block_start_const()` will just crash with a SIGSEGV (or a secondary crash during error reporting when called from `VMError`):
#0 0x00007ffff57d78ce in oopDesc::size_given_klass (this=0x7ffde5616c70, klass=0x7ffda2000000) at /priv/simonisv/OpenJDK/Git/jdk21u-dev/src/hotspot/share/oops/oop.inline.hpp:196
#1 0x00007ffff57d7756 in oopDesc::size (this=0x7ffde5616c70) at /priv/simonisv/OpenJDK/Git/jdk21u-dev/src/hotspot/share/oops/oop.inline.hpp:153
#2 0x00007ffff689a421 in ContiguousSpace::block_start_const (this=0x7ffff004c880, p=0x7ffde5616ca0) at /priv/simonisv/OpenJDK/Git/jdk21u-dev/src/hotspot/share/gc/shared/space.cpp:565
#3 0x00007ffff689b7ba in Space::block_start (this=0x7ffff004c880, p=0x7ffde5616ca0) at /priv/simonisv/OpenJDK/Git/jdk21u-dev/src/hotspot/share/gc/shared/space.inline.hpp:43
#4 0x00007ffff60f4144 in GenerationBlockStartClosure::do_space (this=0x7ffff530ef30, s=0x7ffff004c880) at /priv/simonisv/OpenJDK/Git/jdk21u-dev/src/hotspot/share/gc/shared/generation.cpp:191
#5 0x00007ffff5e560c5 in DefNewGeneration::space_iterate (this=0x7ffff004b9c0, blk=0x7ffff530ef30, usedOnly=false) at /priv/simonisv/OpenJDK/Git/jdk21u-dev/src/hotspot/share/gc/serial/defNewGeneration.cpp:674
#6 0x00007ffff60f3527 in Generation::block_start (this=0x7ffff004b9c0, p=0x7ffde5616ca0) at /priv/simonisv/OpenJDK/Git/jdk21u-dev/src/hotspot/share/gc/shared/generation.cpp:200
#7 0x00007ffff60e36e9 in GenCollectedHeap::block_start (this=0x7ffff0038450, addr=0x7ffde5616ca0) at /priv/simonisv/OpenJDK/Git/jdk21u-dev/src/hotspot/share/gc/shared/genCollectedHeap.cpp:884
#8 0x00007ffff60e5b97 in BlockLocationPrinter<GenCollectedHeap>::base_oop_or_null (addr=0x7ffde5616ca0) at /priv/simonisv/OpenJDK/Git/jdk21u-dev/src/hotspot/share/gc/shared/locationPrinter.inline.hpp:41
#9 0x00007ffff60e592b in BlockLocationPrinter<GenCollectedHeap>::print_location (st=0x7ffff0000b60, addr=0x7ffde5616ca0) at /priv/simonisv/OpenJDK/Git/jdk21u-dev/src/hotspot/share/gc/shared/locationPrinter.inline.hpp:56
#10 0x00007ffff60e43bd in GenCollectedHeap::print_location (this=0x7ffff0038450, st=0x7ffff0000b60, addr=0x7ffde5616ca0) at /priv/simonisv/OpenJDK/Git/jdk21u-dev/src/hotspot/share/gc/shared/genCollectedHeap.cpp:1046
#11 0x00007ffff66acb22 in os::print_location (st=0x7ffff0000b60, x=140728451820704, verbose=false) at /priv/simonisv/OpenJDK/Git/jdk21u-dev/src/hotspot/share/runtime/os.cpp:1190
And that's again because the heap is in general not *walkable* when we call this function. Making it walkable will fill the remaining TLAB spaces with a dummy int array, but without that, we will just trying to interpret random memory (or NULL if running with `-XX:+ZeroTLAB`) as a `Klass` pointer which is seldomly successful :)
> I suspect the following oddly looking code is used to workaround the unimplemented branch of block_start.
>
> ```
> if (DebuggingContext::is_enabled() || VMError::is_error_reported()) {
> return nullptr;
> }
> ```
That "oddly looking code" is actually the proof that `block_start()` only gets called from `VMError` or manually, when natively debugging the VM.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/21870#issuecomment-2454964142
More information about the hotspot-gc-dev
mailing list