8371779: Replace MemTagBitmap with ResourceBitMap

Reviewed-by: azafari, phubner
This commit is contained in:
Johan Sjölen 2025-11-17 09:06:32 +00:00
parent d032b28d9d
commit 970533d41d
2 changed files with 10 additions and 65 deletions

View File

@ -32,7 +32,6 @@
#include "memory/universe.hpp"
#include "nmt/memMapPrinter.hpp"
#include "nmt/memTag.hpp"
#include "nmt/memTagBitmap.hpp"
#include "nmt/memTracker.hpp"
#include "nmt/virtualMemoryTracker.hpp"
#include "runtime/nonJavaThread.hpp"
@ -40,6 +39,8 @@
#include "runtime/thread.hpp"
#include "runtime/threadSMR.hpp"
#include "runtime/vmThread.hpp"
#include "utilities/bitMap.hpp"
#include "utilities/bitMap.inline.hpp"
#include "utilities/globalDefinitions.hpp"
#include "utilities/ostream.hpp"
#include "utilities/permitForbiddenFunctions.hpp"
@ -128,8 +129,8 @@ public:
}
// Given a vma [from, to), find all regions that intersect with this vma and
// return their collective flags.
MemTagBitmap lookup(const void* from, const void* to) const {
// fill out their collective flags into bm.
void lookup(const void* from, const void* to, ResourceBitMap& bm) const {
assert(from <= to, "Sanity");
// We optimize for sequential lookups. Since this class is used when a list
// of OS mappings is scanned (VirtualQuery, /proc/pid/maps), and these lists
@ -138,16 +139,14 @@ public:
// the range is to the right of the given section, we need to re-start the search
_last = 0;
}
MemTagBitmap bm;
for(uintx i = _last; i < _count; i++) {
if (range_intersects(from, to, _ranges[i].from, _ranges[i].to)) {
bm.set_tag(_mem_tags[i]);
bm.set_bit((BitMap::idx_t)_mem_tags[i]);
} else if (to <= _ranges[i].from) {
_last = i;
break;
}
}
return bm;
}
bool do_allocation_site(const ReservedMemoryRegion* rgn) override {
@ -247,11 +246,13 @@ bool MappingPrintSession::print_nmt_info_for_region(const void* vma_from, const
// print NMT information, if available
if (MemTracker::enabled()) {
// Correlate vma region (from, to) with NMT region(s) we collected previously.
const MemTagBitmap flags = _nmt_info.lookup(vma_from, vma_to);
if (flags.has_any()) {
ResourceMark rm;
ResourceBitMap flags(mt_number_of_tags);
_nmt_info.lookup(vma_from, vma_to, flags);
if (!flags.is_empty()) {
for (int i = 0; i < mt_number_of_tags; i++) {
const MemTag mem_tag = (MemTag)i;
if (flags.has_tag(mem_tag)) {
if (flags.at((BitMap::idx_t)mem_tag)) {
if (num_printed > 0) {
_out->put(',');
}

View File

@ -1,56 +0,0 @@
/*
* Copyright (c) 2023, 2024, Red Hat, Inc. All rights reserved.
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#ifndef SHARE_NMT_MEMTAGBITMAP_HPP
#define SHARE_NMT_MEMTAGBITMAP_HPP
#include "nmt/memTag.hpp"
#include "utilities/debug.hpp"
#include "utilities/globalDefinitions.hpp"
class MemTagBitmap {
uint32_t _v;
STATIC_ASSERT(sizeof(_v) * BitsPerByte >= mt_number_of_tags);
public:
MemTagBitmap(uint32_t v = 0) : _v(v) {}
MemTagBitmap(const MemTagBitmap& o) : _v(o._v) {}
uint32_t raw_value() const { return _v; }
void set_tag(MemTag mem_tag) {
const int bitno = (int)mem_tag;
_v |= nth_bit(bitno);
}
bool has_tag(MemTag mem_tag) const {
const int bitno = (int)mem_tag;
return _v & nth_bit(bitno);
}
bool has_any() const { return _v > 0; }
};
#endif // SHARE_NMT_MEMTAGBITMAP_HPP