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

Stefan Karlsson stefank at openjdk.org
Mon Sep 30 08:38:37 UTC 2024


On Mon, 30 Sep 2024 06:20:37 GMT, Kim Barrett <kbarrett 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
>
> 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.)

FWIW, we had a similar discussion in #19435.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/21206#discussion_r1780664025


More information about the hotspot-runtime-dev mailing list