RFR: 8341020: Metaspace::contains crashes when Metaspace is not fully initialized

Kim Barrett kbarrett at openjdk.org
Mon Sep 30 06:23:36 UTC 2024


On Thu, 26 Sep 2024 11:44:44 GMT, Aleksey Shipilev <shade at openjdk.org> wrote:

> When debugging CDS, I asked for `os::print_location` when Metaspace was not completely initialized. I suspect the same might happen if error handler fires very early in startup sequence.
> 
> `os::print_location` got to `Metaspace::contains`, which ended up in `Metaspace::is_in_nonclass_metaspace`, which crashed, since `VirtualSpaceList` was null. Other checks in `Metaspace::contains` seem to only check the address against the boundaries, and are not affected.
> 
> Additional testing:
>  - [x] The same debugging session did not crash the VM after the patch

Changes requested by kbarrett (Reviewer).

src/hotspot/share/memory/metaspace.cpp line 996:

> 994: bool Metaspace::is_in_nonclass_metaspace(const void* ptr) {
> 995:   VirtualSpaceList* list = VirtualSpaceList::vslist_nonclass();
> 996:   return (list != nullptr) && list->contains((MetaWord*) ptr);

I'm not sure about this. This, and a number of other related functions nearby,
all seem like they should have Metaspace::initialized() as a precondition. And
the call to Metaspace::contains in os::print_location should be conditional on
Metaspace::initialized().  (There may be other "is initialized" checks that
should be made by (and offered to) os::print_location, but that's beyond the
scope of this change.)

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

PR Review: https://git.openjdk.org/jdk/pull/21206#pullrequestreview-2336486561
PR Review Comment: https://git.openjdk.org/jdk/pull/21206#discussion_r1780499090


More information about the hotspot-runtime-dev mailing list