Skip to content

8337217: Port VirtualMemoryTracker to use VMATree #20425

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
33326b0
handle null argument
wenshao Jul 19, 2024
d044ef7
first tests passed
afshin-zafari Jul 25, 2024
ebd029d
added performance tests.
afshin-zafari Jul 30, 2024
ac1befc
review comments applied (round 01)
afshin-zafari Aug 4, 2024
0c7141a
Merge branch 'openjdk:master' into _8337217_nmt_VMT_with_tree
afshin-zafari Aug 4, 2024
9df7cff
Merge branch '_8337217_nmt_VMT_with_tree' of http://github.com/afshin…
afshin-zafari Aug 4, 2024
b83ef25
some fixes and improvements.
afshin-zafari Aug 5, 2024
f414999
review comments applied (round 2).
afshin-zafari Aug 5, 2024
3ed28c2
performance test compares SSL with Treap.
afshin-zafari Aug 7, 2024
733fb42
some fixes for type casting for builds on other platforms. And perfor…
afshin-zafari Aug 7, 2024
c138aed
missing type-casts fixed.
afshin-zafari Aug 7, 2024
195c2b8
review comments applied (round 3).
afshin-zafari Aug 12, 2024
3335a7c
Merge branch 'master' into _8337217_nmt_VMT_with_tree
afshin-zafari Aug 12, 2024
691811c
fixed GHA build failures.
afshin-zafari Aug 12, 2024
979d14d
removed one more pointer. fixed a gtest failure.
afshin-zafari Aug 13, 2024
4f68ddd
fixed test failures in GHA.
afshin-zafari Aug 13, 2024
e671e9b
fixes of GHA failures.
afshin-zafari Aug 13, 2024
67ee177
fixes for GHA failures.
afshin-zafari Aug 13, 2024
a126576
missing stack call sites are tolerable in NEW version tests.
afshin-zafari Aug 14, 2024
1d768a0
some name refactoring
afshin-zafari Aug 14, 2024
54fdb59
fixes on coding style.
afshin-zafari Aug 20, 2024
6e08f10
Merge branch 'master' into _8337217_nmt_VMT_with_tree
afshin-zafari Aug 20, 2024
2553d1e
some fixes
afshin-zafari Aug 30, 2024
347726c
check when stack-index is invalid.
afshin-zafari Sep 2, 2024
8c5c5bd
merge master into branch
afshin-zafari Sep 2, 2024
065d5c1
set_flagand size arg + Johan's feedback.
afshin-zafari Sep 23, 2024
5d9ccdf
shenandoah fixes.
afshin-zafari Sep 23, 2024
31ce4d3
comments applied.
afshin-zafari Sep 27, 2024
0ab316c
print format fixed
afshin-zafari Sep 27, 2024
907e1e9
build failure fixed.
afshin-zafari Sep 27, 2024
22034bf
more fix.
afshin-zafari Sep 27, 2024
72af169
only 1 version of VMT
afshin-zafari Sep 28, 2024
1e92315
Merge remote-tracking branch 'origin/master' into _8337217_nmt_VMT_wi…
afshin-zafari Sep 30, 2024
3c66997
Johan's feedback.
afshin-zafari Oct 14, 2024
b70e15d
fixed hpp gaurd of vmtCommon.
afshin-zafari Oct 14, 2024
55e5c64
removed unnecessary line from visit committed region function.
afshin-zafari Oct 14, 2024
b4687d1
snaphot thread stack updated and tested.
afshin-zafari Oct 16, 2024
cced79a
Merge remote-tracking branch 'origin/master' into _8337217_nmt_VMT_wi…
afshin-zafari Oct 16, 2024
69b19a4
Merge remote-tracking branch 'origin/master' into _8337217_nmt_VMT_wi…
afshin-zafari Oct 16, 2024
9c3324f
fixed merged glitches.
afshin-zafari Oct 16, 2024
99b2327
fixes after merge with use_tag_inplace
afshin-zafari Oct 20, 2024
da8b4de
Merge remote-tracking branch 'origin/master' into _8337217_nmt_VMT_wi…
afshin-zafari Nov 7, 2024
1e4fbf2
added some descriptions of how VMT works.
afshin-zafari Nov 8, 2024
52631e4
Merge remote-tracking branch 'origin/master' into _8337217_nmt_VMT_wi…
afshin-zafari Nov 11, 2024
7bd065e
gc/x directory removed.
afshin-zafari Nov 11, 2024
ee639f1
Merge remote-tracking branch 'origin/master' into _8337217_nmt_VMT_wi…
afshin-zafari Nov 18, 2024
026256f
Roberto's feedback applied.
afshin-zafari Nov 25, 2024
451b904
Merge remote-tracking branch 'origin/master' into _8337217_nmt_VMT_wi…
afshin-zafari Nov 25, 2024
771cb02
some fixes.
afshin-zafari Dec 2, 2024
7fc7b34
Merge remote-tracking branch 'origin/master' into _8337217_nmt_VMT_wi…
afshin-zafari Dec 2, 2024
fd77057
a missed change in a shenandoah file.
afshin-zafari Dec 2, 2024
b5e6d26
removed unused local var.
afshin-zafari Dec 9, 2024
316d9a1
visit_committed_regions signature changed.
afshin-zafari Dec 10, 2024
7b0c427
visit committed regions refined.
afshin-zafari Dec 13, 2024
2afb8c7
Merge remote-tracking branch 'origin/master' into _8337217_nmt_VMT_wi…
afshin-zafari Jan 8, 2025
f69e757
added overlap checks.
afshin-zafari Jan 14, 2025
b1b5aa0
fix for debug prints
afshin-zafari Jan 14, 2025
abaf0b3
size_t format fixed.
afshin-zafari Jan 14, 2025
c8aa9c5
undo overlapping checks.
afshin-zafari Jan 17, 2025
aa75ab7
Merge remote-tracking branch 'origin/master' into _8337217_nmt_VMT_wi…
afshin-zafari Jan 17, 2025
5352894
one small fix for SSIZE_FORMAT
afshin-zafari Jan 24, 2025
5429e79
merge with master
afshin-zafari Jan 27, 2025
692987e
merge with the new lock mechanism for NMT
afshin-zafari Jan 29, 2025
c0670b6
Merge remote-tracking branch 'origin/master' into _8337217_nmt_VMT_wi…
afshin-zafari Jan 30, 2025
a0d133f
fix in shendoahCardTable
afshin-zafari Jan 30, 2025
873d535
fixed merge problems
afshin-zafari Feb 6, 2025
35c11b9
removed vmtCommon.hpp
afshin-zafari Feb 11, 2025
611a2d4
flag/type -> tag chages are removed.
afshin-zafari Feb 13, 2025
7640108
missed flag/tag -> type
afshin-zafari Feb 21, 2025
92f2bfd
Merge remote-tracking branch 'origin/master' into _8337217_nmt_VMT_wi…
afshin-zafari Feb 21, 2025
18ec1db
undo stringopts.cpp changes
afshin-zafari Feb 21, 2025
a89a013
removed the size par from set_..._tag
afshin-zafari Feb 23, 2025
39f7482
removed remaining of the unrelated changes.
afshin-zafari Feb 23, 2025
0a61fec
once more.
afshin-zafari Feb 23, 2025
5f4bc6d
test file got back, fixed coding style
afshin-zafari Feb 24, 2025
5aa4556
reviews applied.
afshin-zafari Feb 25, 2025
74e4872
removed UseFlagInPlace test.
afshin-zafari Feb 27, 2025
7020958
style, some cleanup, VMT and regionsTree circular dep resolved
afshin-zafari Feb 28, 2025
fc106d5
test cases for doing reserve or commit the same region twice.
afshin-zafari Mar 4, 2025
f2f1a80
review comments applied
afshin-zafari Mar 6, 2025
cfab60f
more reviews.
afshin-zafari Mar 7, 2025
5177cc1
Merge remote-tracking branch 'origin/master' into _8337217_nmt_VMT_wi…
afshin-zafari Mar 7, 2025
95198a8
Merge remote-tracking branch 'origin/master' into _8337217_nmt_VMT_wi…
afshin-zafari Apr 11, 2025
9010b68
fixes after merge with master.
afshin-zafari Apr 11, 2025
43d7b08
Merge remote-tracking branch 'origin/master' into _8337217_nmt_VMT_wi…
afshin-zafari Jun 13, 2025
e303ee7
changes after merge
afshin-zafari Jun 13, 2025
815092d
fixes to a few failures.
afshin-zafari Jun 17, 2025
ac15158
copyright years
afshin-zafari Jun 18, 2025
66ddc67
Merge remote-tracking branch 'origin/master' into _8337217_nmt_VMT_wi…
afshin-zafari Jun 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/hotspot/share/nmt/memBaseline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ bool MemBaseline::baseline_allocation_sites() {

// Virtual memory allocation sites
VirtualMemoryAllocationWalker virtual_memory_walker;
if (!VirtualMemoryTracker::walk_virtual_memory(&virtual_memory_walker)) {
if (!VirtualMemoryTracker::Instance::walk_virtual_memory(&virtual_memory_walker)) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/nmt/memMapPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class CachedNMTInformation : public VirtualMemoryWalker {

// Iterate all NMT virtual memory regions and fill this cache.
bool fill_from_nmt() {
return VirtualMemoryTracker::walk_virtual_memory(this);
return VirtualMemoryTracker::Instance::walk_virtual_memory(this);
}
};

Expand Down
44 changes: 29 additions & 15 deletions src/hotspot/share/nmt/memReporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@
*
*/
#include "cds/filemap.hpp"
#include "logging/log.hpp"
#include "memory/metaspace.hpp"
#include "memory/metaspaceUtils.hpp"
#include "nmt/mallocTracker.hpp"
#include "nmt/memTag.hpp"
#include "nmt/memReporter.hpp"
#include "nmt/memTracker.hpp"
#include "nmt/memoryFileTracker.hpp"
#include "nmt/regionsTree.hpp"
#include "nmt/regionsTree.inline.hpp"
#include "nmt/threadStackTracker.hpp"
#include "nmt/virtualMemoryTracker.hpp"
#include "utilities/debug.hpp"
Expand Down Expand Up @@ -432,34 +435,45 @@ void MemDetailReporter::report_virtual_memory_region(const ReservedMemoryRegion*
}

if (all_committed) {
CommittedRegionIterator itr = reserved_rgn->iterate_committed_regions();
const CommittedMemoryRegion* committed_rgn = itr.next();
if (committed_rgn->size() == reserved_rgn->size() && committed_rgn->call_stack()->equals(*stack)) {
// One region spanning the entire reserved region, with the same stack trace.
// Don't print this regions because the "reserved and committed" line above
// already indicates that the region is committed.
assert(itr.next() == nullptr, "Unexpectedly more than one regions");
bool reserved_and_committed = false;
VirtualMemoryTracker::Instance::tree()->visit_committed_regions(*reserved_rgn,
[&](CommittedMemoryRegion& committed_rgn) {
if (committed_rgn.equals(*reserved_rgn)) {
// One region spanning the entire reserved region, with the same stack trace.
// Don't print this regions because the "reserved and committed" line above
// already indicates that the region is committed.
reserved_and_committed = true;
return false;
}
return true;
});

if (reserved_and_committed) {
return;
}
}

CommittedRegionIterator itr = reserved_rgn->iterate_committed_regions();
const CommittedMemoryRegion* committed_rgn;
while ((committed_rgn = itr.next()) != nullptr) {
auto print_committed_rgn = [&](const CommittedMemoryRegion& crgn) {
// Don't report if size is too small
if (amount_in_current_scale(committed_rgn->size()) == 0) continue;
stack = committed_rgn->call_stack();
if (amount_in_current_scale(crgn.size()) == 0) return;
stack = crgn.call_stack();
out->cr();
INDENT_BY(8,
print_virtual_memory_region("committed", committed_rgn->base(), committed_rgn->size());
print_virtual_memory_region("committed", crgn.base(), crgn.size());
if (stack->is_empty()) {
out->cr();
} else {
out->print_cr(" from");
INDENT_BY(4, stack->print_on(out);)
INDENT_BY(4, _stackprinter.print_stack(stack);)
}
)
}
};

VirtualMemoryTracker::Instance::tree()->visit_committed_regions(*reserved_rgn,
[&](CommittedMemoryRegion& crgn) {
print_committed_rgn(crgn);
return true;
});
}

void MemDetailReporter::report_memory_file_allocations() {
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/share/nmt/memTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void MemTracker::initialize() {
_baseline.initialize();
if (!MallocTracker::initialize(level) ||
!MemoryFileTracker::Instance::initialize(level) ||
!VirtualMemoryTracker::initialize(level)) {
!VirtualMemoryTracker::Instance::initialize(level)) {
assert(false, "NMT initialization failed");
level = NMT_off;
log_warning(nmt)("NMT initialization failed. NMT disabled.");
Expand Down Expand Up @@ -126,7 +126,7 @@ void MemTracker::final_report(outputStream* output) {
bool MemTracker::print_containing_region(const void* p, outputStream* out) {
return enabled() &&
(MallocTracker::print_pointer_information(p, out) ||
VirtualMemoryTracker::print_containing_region(p, out));
VirtualMemoryTracker::Instance::print_containing_region(p, out));
}

void MemTracker::report(bool summary_only, outputStream* output, size_t scale) {
Expand Down
16 changes: 8 additions & 8 deletions src/hotspot/share/nmt/memTracker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,23 +132,23 @@ class MemTracker : AllStatic {
if (!enabled()) return;
if (addr != nullptr) {
NmtVirtualMemoryLocker nvml;
VirtualMemoryTracker::add_reserved_region((address)addr, size, stack, mem_tag);
VirtualMemoryTracker::Instance::add_reserved_region((address)addr, size, stack, mem_tag);
}
}

static inline void record_virtual_memory_release(void* addr, size_t size) {
assert_post_init();
if (!enabled()) return;
if (addr != nullptr) {
VirtualMemoryTracker::remove_released_region((address)addr, size);
VirtualMemoryTracker::Instance::remove_released_region((address)addr, size);
}
}

static inline void record_virtual_memory_uncommit(void* addr, size_t size) {
assert_post_init();
if (!enabled()) return;
if (addr != nullptr) {
VirtualMemoryTracker::remove_uncommitted_region((address)addr, size);
VirtualMemoryTracker::Instance::remove_uncommitted_region((address)addr, size);
}
}

Expand All @@ -158,8 +158,8 @@ class MemTracker : AllStatic {
if (!enabled()) return;
if (addr != nullptr) {
NmtVirtualMemoryLocker nvml;
VirtualMemoryTracker::add_reserved_region((address)addr, size, stack, mem_tag);
VirtualMemoryTracker::add_committed_region((address)addr, size, stack);
VirtualMemoryTracker::Instance::add_reserved_region((address)addr, size, stack, mem_tag);
VirtualMemoryTracker::Instance::add_committed_region((address)addr, size, stack);
}
}

Expand All @@ -169,7 +169,7 @@ class MemTracker : AllStatic {
if (!enabled()) return;
if (addr != nullptr) {
NmtVirtualMemoryLocker nvml;
VirtualMemoryTracker::add_committed_region((address)addr, size, stack);
VirtualMemoryTracker::Instance::add_committed_region((address)addr, size, stack);
}
}

Expand Down Expand Up @@ -217,7 +217,7 @@ class MemTracker : AllStatic {
if (!enabled()) return;
if (addr != nullptr) {
NmtVirtualMemoryLocker nvml;
VirtualMemoryTracker::split_reserved_region((address)addr, size, split, mem_tag, split_tag);
VirtualMemoryTracker::Instance::split_reserved_region((address)addr, size, split, mem_tag, split_tag);
}
}

Expand All @@ -230,7 +230,7 @@ class MemTracker : AllStatic {
if (!enabled()) return;
if (addr != nullptr) {
NmtVirtualMemoryLocker nvml;
VirtualMemoryTracker::set_reserved_region_type((address)addr, size, mem_tag);
VirtualMemoryTracker::Instance::set_reserved_region_tag((address)addr, size, mem_tag);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/hotspot/share/nmt/memoryFileTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void MemoryFileTracker::print_report_on(const MemoryFile* file, outputStream* st
if (prev == nullptr) {
// Must be first node.
prev = current;
return;
return true;
}
#ifdef ASSERT
if (broken_start != nullptr && prev->val().out.mem_tag() != current->val().in.mem_tag()) {
Expand All @@ -96,6 +96,7 @@ void MemoryFileTracker::print_report_on(const MemoryFile* file, outputStream* st
stream->cr();
}
prev = current;
return true;
});
#ifdef ASSERT
if (broken_start != nullptr) {
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/nmt/memoryFileTracker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
#include "memory/allocation.hpp"
#include "nmt/nmtCommon.hpp"
#include "nmt/nmtNativeCallStackStorage.hpp"
#include "nmt/virtualMemoryTracker.hpp"
#include "nmt/vmatree.hpp"
#include "nmt/virtualMemoryTracker.hpp"
#include "runtime/os.inline.hpp"
#include "utilities/growableArray.hpp"
#include "utilities/nativeCallStack.hpp"
Expand Down
12 changes: 9 additions & 3 deletions src/hotspot/share/nmt/nmtTreap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ template<typename K, typename V, typename COMPARATOR, typename ALLOCATOR>
class Treap {
friend class NMTVMATreeTest;
friend class NMTTreapTest;
friend class VMTWithVMATreeTest;
public:
class TreapNode {
friend Treap;
Expand Down Expand Up @@ -212,12 +213,13 @@ class Treap {
seen_count++;
if (last_seen == nullptr) {
last_seen = node;
return;
return true;
}
if (COMPARATOR::cmp(last_seen->key(), node->key()) > 0) {
failed = false;
}
last_seen = node;
return true;
});
assert(seen_count == _node_count, "the number of visited nodes do not match with the number of stored nodes");
assert(!failed, "keys was not monotonically strongly increasing when visiting in order");
Expand Down Expand Up @@ -382,7 +384,9 @@ class Treap {
head = head->left();
}
head = to_visit.pop();
f(head);
if (!f(head)) {
return;
}
head = head->right();
}
}
Expand All @@ -409,7 +413,9 @@ class Treap {
const int cmp_from = COMPARATOR::cmp(head->key(), from);
const int cmp_to = COMPARATOR::cmp(head->key(), to);
if (cmp_from >= 0 && cmp_to < 0) {
f(head);
if (!f(head)) {
return;
}
}
if (cmp_to < 0) {
head = head->right();
Expand Down
3 changes: 1 addition & 2 deletions src/hotspot/share/nmt/nmtUsage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include "nmt/nmtCommon.hpp"
#include "nmt/nmtUsage.hpp"
#include "nmt/threadStackTracker.hpp"
#include "nmt/virtualMemoryTracker.hpp"

// Enabled all options for snapshot.
const NMTUsageOptions NMTUsage::OptionsAll = { true, true, true };
Expand All @@ -48,7 +47,7 @@ void NMTUsage::walk_thread_stacks() {
// much memory had been committed if they are backed by virtual memory. This
// needs to happen before we take the snapshot of the virtual memory since it
// will update this information.
VirtualMemoryTracker::snapshot_thread_stacks();
VirtualMemoryTracker::Instance::snapshot_thread_stacks();
}

void NMTUsage::update_malloc_usage() {
Expand Down
57 changes: 57 additions & 0 deletions src/hotspot/share/nmt/regionsTree.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2025, 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.
*
*/
#include "nmt/regionsTree.hpp"

VMATree::SummaryDiff RegionsTree::commit_region(address addr, size_t size, const NativeCallStack& stack) {
return commit_mapping((VMATree::position)addr, size, make_region_data(stack, mtNone), /*use tag inplace*/ true);
}

VMATree::SummaryDiff RegionsTree::uncommit_region(address addr, size_t size) {
return uncommit_mapping((VMATree::position)addr, size, make_region_data(NativeCallStack::empty_stack(), mtNone));
}

#ifdef ASSERT
void RegionsTree::NodeHelper::print_on(outputStream* st) {
auto st_str = [&](VMATree::StateType s){
return s == VMATree::StateType::Released ? "Rl" :
s == VMATree::StateType::Reserved ? "Rv" : "Cm";
};
st->print_cr("pos: " INTPTR_FORMAT " "
"%s, %s <|> %s, %s",
p2i((address)position()),
st_str(in_state()),
NMTUtil::tag_to_name(in_tag()),
st_str(out_state()),
NMTUtil::tag_to_name(out_tag())
);
}

void RegionsTree::print_on(outputStream* st) {
visit_in_order([&](Node* node) {
NodeHelper curr(node);
curr.print_on(st);
return true;
});
}
#endif
Loading