RFR: 8356228: NMT does not record reserved memory base address correctly

Afshin Zafari azafari at openjdk.org
Wed Jun 11 11:12:30 UTC 2025


On Wed, 11 Jun 2025 11:06:55 GMT, Afshin Zafari <azafari at openjdk.org> wrote:

>> src/hotspot/share/cds/archiveBuilder.cpp line 346:
>> 
>>> 344:   // During an aligned reserve, some extra sub-regions of the memory region may be released due to alignment requirements.
>>> 345:   // NMT will ignore releasing sub-regions (i.e., contained in other regions) that have mtClassShared tags.
>>> 346:   MemTracker::record_virtual_memory_tag(rs, mtClassShared);
>> 
>> Is it possible to capture this logic in a test, so we can always check for this behavior?
>> 
>> Where in the code do we release and check for the special case of `mtClassShared`?
>> 
>> I'm not 100% sure I understand why we have to first reserve with `mtNone` and only then change it to `mtClassShared`. Why can't we reserve with `mtClassShared` right from the start?
>
>> Is it possible to capture this logic in a test, so we can always check for this behavior?
> 
> Work on it.

> Where in the code do we release and check for the special case of `mtClassShared`?

In `virtualMemoryTracker.cpp, remove_released_region(adddress, size)` in an `if` block as this:

if (reserved_rgn->mem_tag() == mtClassShared) {
    if (reserved_rgn->contain_region(addr, size)) {
      // This is an unmapped CDS region, which is part of the reserved shared
      // memory region.
      // See special handling in VirtualMemoryTracker::add_reserved_region also.
      return true;
    }

    if (size > reserved_rgn->size()) {
      // This is from release the whole region spanning from archive space to class space,
      // so we release them altogether.
      ReservedMemoryRegion class_rgn(addr + reserved_rgn->size(),
                                     (size - reserved_rgn->size()));
      ReservedMemoryRegion* cls_rgn = _reserved_regions->find(class_rgn);
      assert(cls_rgn != nullptr, "Class space region  not recorded?");
      assert(cls_rgn->mem_tag() == mtClass, "Must be class mem tag");
      remove_released_region(reserved_rgn);
      remove_released_region(cls_rgn);
      return true;
    }
  }

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

PR Review Comment: https://git.openjdk.org/jdk/pull/25719#discussion_r2139864313


More information about the hotspot-runtime-dev mailing list