Skip to content

Commit a7255f9

Browse files
author
Afshin Zafari
committed
8366241: NMT: Consolidate [Virtual/Committed/Reserved]Regions into one structure
Reviewed-by: phubner, jsjolen
1 parent 5a08374 commit a7255f9

File tree

12 files changed

+239
-293
lines changed

12 files changed

+239
-293
lines changed

src/hotspot/share/nmt/memBaseline.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -168,12 +168,13 @@ int compare_allocation_site(const VirtualMemoryAllocationSite& s1,
168168
}
169169

170170
bool MemBaseline::aggregate_virtual_memory_allocation_sites() {
171+
171172
SortedLinkedList<VirtualMemoryAllocationSite, compare_allocation_site> allocation_sites;
172173

173174
VirtualMemoryAllocationSite* site;
174175
bool failed_oom = false;
175-
_vma_allocations->visit_reserved_regions([&](ReservedMemoryRegion& rgn) {
176-
VirtualMemoryAllocationSite tmp(*rgn.call_stack(), rgn.mem_tag());
176+
_vma_allocations->visit_reserved_regions([&](VirtualMemoryRegion& rgn) {
177+
VirtualMemoryAllocationSite tmp(*rgn.reserved_call_stack(), rgn.mem_tag());
177178
site = allocation_sites.find(tmp);
178179
if (site == nullptr) {
179180
LinkedListNode<VirtualMemoryAllocationSite>* node =

src/hotspot/share/nmt/memMapPrinter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2023, 2026, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2023, 2024, Red Hat, Inc. and/or its affiliates.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
@@ -149,7 +149,7 @@ class CachedNMTInformation : public VirtualMemoryWalker {
149149
}
150150
}
151151

152-
bool do_allocation_site(const ReservedMemoryRegion* rgn) override {
152+
bool do_allocation_site(const VirtualMemoryRegion* rgn) override {
153153
// Cancel iteration if we run out of memory (add returns false);
154154
return add(rgn->base(), rgn->end(), rgn->mem_tag());
155155
}

src/hotspot/share/nmt/memReporter.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -395,14 +395,14 @@ int MemDetailReporter::report_virtual_memory_allocation_sites() {
395395
void MemDetailReporter::report_virtual_memory_map() {
396396
// Virtual memory map always in base address order
397397
output()->print_cr("Virtual memory map:");
398-
_baseline.virtual_memory_allocations()->visit_reserved_regions([&](ReservedMemoryRegion& rgn) {
398+
_baseline.virtual_memory_allocations()->visit_reserved_regions([&](VirtualMemoryRegion& rgn) {
399399
report_virtual_memory_region(&rgn);
400400
return true;
401401
});
402402
}
403403

404-
void MemDetailReporter::report_virtual_memory_region(const ReservedMemoryRegion* reserved_rgn) {
405-
assert(reserved_rgn != nullptr, "null pointer");
404+
void MemDetailReporter::report_virtual_memory_region(const VirtualMemoryRegion* rgn) {
405+
assert(rgn != nullptr, "null pointer");
406406

407407
// We don't bother about reporting peaks here.
408408
// That is because peaks - in the context of virtual memory, peak of committed areas - make little sense
@@ -414,16 +414,16 @@ void MemDetailReporter::report_virtual_memory_region(const ReservedMemoryRegion*
414414
// usage *by callsite*.
415415

416416
// Don't report if size is too small.
417-
if (amount_in_current_scale(reserved_rgn->size()) == 0) return;
417+
if (amount_in_current_scale(rgn->size()) == 0) return;
418418

419419
outputStream* out = output();
420420
const char* scale = current_scale();
421-
const NativeCallStack* stack = reserved_rgn->call_stack();
422-
bool all_committed = reserved_rgn->size() == _baseline.virtual_memory_allocations()->committed_size(*reserved_rgn);
421+
const NativeCallStack* stack = rgn->reserved_call_stack();
422+
bool all_committed = rgn->size() == _baseline.virtual_memory_allocations()->committed_size(*rgn);
423423
const char* region_type = (all_committed ? "reserved and committed" : "reserved");
424424
out->cr();
425-
print_virtual_memory_region(region_type, reserved_rgn->base(), reserved_rgn->size());
426-
out->print(" for %s", NMTUtil::tag_to_name(reserved_rgn->mem_tag()));
425+
print_virtual_memory_region(region_type, rgn->base(), rgn->size());
426+
out->print(" for %s", NMTUtil::tag_to_name(rgn->mem_tag()));
427427
if (stack->is_empty()) {
428428
out->cr();
429429
} else {
@@ -433,9 +433,9 @@ void MemDetailReporter::report_virtual_memory_region(const ReservedMemoryRegion*
433433

434434
if (all_committed) {
435435
bool reserved_and_committed = false;
436-
_baseline.virtual_memory_allocations()->visit_committed_regions(*reserved_rgn,
437-
[&](CommittedMemoryRegion& committed_rgn) {
438-
if (committed_rgn.equals(*reserved_rgn)) {
436+
_baseline.virtual_memory_allocations()->visit_committed_regions(*rgn,
437+
[&](VirtualMemoryRegion& committed_rgn) {
438+
if (committed_rgn.equals(*rgn)) {
439439
// One region spanning the entire reserved region, with the same stack trace.
440440
// Don't print this regions because the "reserved and committed" line above
441441
// already indicates that the region is committed.
@@ -450,13 +450,13 @@ void MemDetailReporter::report_virtual_memory_region(const ReservedMemoryRegion*
450450
}
451451
}
452452

453-
auto print_committed_rgn = [&](const CommittedMemoryRegion& crgn) {
453+
auto print_committed_rgn = [&](const VirtualMemoryRegion& rgn) {
454454
// Don't report if size is too small
455-
if (amount_in_current_scale(crgn.size()) == 0) return;
456-
stack = crgn.call_stack();
455+
if (amount_in_current_scale(rgn.size()) == 0) return;
456+
stack = rgn.committed_call_stack();
457457
out->cr();
458458
INDENT_BY(8,
459-
print_virtual_memory_region("committed", crgn.base(), crgn.size());
459+
print_virtual_memory_region("committed", rgn.base(), rgn.size());
460460
if (stack->is_empty()) {
461461
out->cr();
462462
} else {
@@ -466,9 +466,9 @@ void MemDetailReporter::report_virtual_memory_region(const ReservedMemoryRegion*
466466
)
467467
};
468468

469-
_baseline.virtual_memory_allocations()->visit_committed_regions(*reserved_rgn,
470-
[&](CommittedMemoryRegion& crgn) {
471-
print_committed_rgn(crgn);
469+
_baseline.virtual_memory_allocations()->visit_committed_regions(*rgn,
470+
[&](VirtualMemoryRegion& committed_rgn) {
471+
print_committed_rgn(committed_rgn);
472472
return true;
473473
});
474474
}

src/hotspot/share/nmt/memReporter.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -178,7 +178,7 @@ class MemDetailReporter : public MemSummaryReporter {
178178
int report_virtual_memory_allocation_sites();
179179

180180
// Report a virtual memory region
181-
void report_virtual_memory_region(const ReservedMemoryRegion* rgn);
181+
void report_virtual_memory_region(const VirtualMemoryRegion* rgn);
182182
};
183183

184184
/*

src/hotspot/share/nmt/regionsTree.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2025, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -58,9 +58,9 @@ void RegionsTree::print_on(outputStream* st) {
5858
}
5959
#endif
6060

61-
size_t RegionsTree::committed_size(const ReservedMemoryRegion& rgn) {
61+
size_t RegionsTree::committed_size(const VirtualMemoryRegion& rgn) {
6262
size_t result = 0;
63-
visit_committed_regions(rgn, [&](CommittedMemoryRegion& crgn) {
63+
visit_committed_regions(rgn, [&](VirtualMemoryRegion& crgn) {
6464
result += crgn.size();
6565
return true;
6666
});

src/hotspot/share/nmt/regionsTree.hpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2025, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -29,8 +29,7 @@
2929
#include "nmt/vmatree.hpp"
3030

3131

32-
class ReservedMemoryRegion;
33-
class CommittedMemoryRegion;
32+
class VirtualMemoryRegion;
3433
// RegionsTree extends VMATree to add some more specific API and also defines a helper
3534
// for processing the tree nodes in a shorter and more meaningful way.
3635
class RegionsTree : public VMATree {
@@ -46,7 +45,7 @@ class RegionsTree : public VMATree {
4645
_with_storage(other._with_storage) {}
4746
RegionsTree& operator=(const RegionsTree& other) = delete;
4847

49-
ReservedMemoryRegion find_reserved_region(address addr);
48+
VirtualMemoryRegion find_reserved_region(address addr);
5049

5150
void commit_region(address addr, size_t size, const NativeCallStack& stack, SummaryDiff& diff);
5251
void uncommit_region(address addr, size_t size, SummaryDiff& diff);
@@ -71,6 +70,7 @@ class RegionsTree : public VMATree {
7170
return position() - other.position();
7271
}
7372
inline NativeCallStackStorage::StackIndex out_stack_index() const { return _node->val().out.reserved_stack(); }
73+
inline NativeCallStackStorage::StackIndex out_committed_stack_index() const { return _node->val().out.committed_stack(); }
7474
inline MemTag in_tag() const { return _node->val().in.mem_tag(); }
7575
inline MemTag out_tag() const { return _node->val().out.mem_tag(); }
7676
inline void set_in_tag(MemTag tag) { _node->val().in.set_tag(tag); }
@@ -81,7 +81,7 @@ class RegionsTree : public VMATree {
8181
DEBUG_ONLY(void print_on(outputStream* st);)
8282

8383
template<typename F>
84-
void visit_committed_regions(const ReservedMemoryRegion& rgn, F func);
84+
void visit_committed_regions(const VirtualMemoryRegion& rgn, F func);
8585

8686
template<typename F>
8787
void visit_reserved_regions(F func);
@@ -90,15 +90,23 @@ class RegionsTree : public VMATree {
9090
return RegionData(_ncs_storage.push(ncs), tag);
9191
}
9292

93-
inline const NativeCallStack stack(NodeHelper& node) {
93+
inline const NativeCallStack reserved_stack(NodeHelper& node) {
9494
if (!_with_storage) {
9595
return NativeCallStack::empty_stack();
9696
}
9797
NativeCallStackStorage::StackIndex si = node.out_stack_index();
9898
return _ncs_storage.get(si);
9999
}
100100

101-
size_t committed_size(const ReservedMemoryRegion& rgn);
101+
inline const NativeCallStack committed_stack(NodeHelper& node) {
102+
if (!_with_storage) {
103+
return NativeCallStack::empty_stack();
104+
}
105+
NativeCallStackStorage::StackIndex si = node.out_committed_stack_index();
106+
return _ncs_storage.get(si);
107+
}
108+
109+
size_t committed_size(const VirtualMemoryRegion& rgn);
102110
};
103111

104112
#endif // NMT_REGIONSTREE_HPP

src/hotspot/share/nmt/regionsTree.inline.hpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2025, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -29,7 +29,7 @@
2929
#include "nmt/virtualMemoryTracker.hpp"
3030

3131
template<typename F>
32-
void RegionsTree::visit_committed_regions(const ReservedMemoryRegion& rgn, F func) {
32+
void RegionsTree::visit_committed_regions(const VirtualMemoryRegion& rgn, F func) {
3333
position start = (position)rgn.base();
3434
size_t end = reinterpret_cast<size_t>(rgn.end()) + 1;
3535
size_t comm_size = 0;
@@ -38,8 +38,12 @@ void RegionsTree::visit_committed_regions(const ReservedMemoryRegion& rgn, F fun
3838
visit_range_in_order(start, end, [&](Node* node) {
3939
NodeHelper curr(node);
4040
if (prev.is_valid() && prev.is_committed_begin()) {
41-
CommittedMemoryRegion cmr((address)prev.position(), curr.distance_from(prev), stack(prev));
42-
if (!func(cmr)) {
41+
VirtualMemoryRegion rgn((address)prev.position(),
42+
curr.distance_from(prev),
43+
reserved_stack(prev),
44+
committed_stack(prev),
45+
prev.out_tag());
46+
if (!func(rgn)) {
4347
return false;
4448
}
4549
}
@@ -63,13 +67,13 @@ void RegionsTree::visit_reserved_regions(F func) {
6367
}
6468
prev = curr;
6569
if (curr.is_released_begin() || begin_node.out_tag() != curr.out_tag()) {
66-
auto st = stack(begin_node);
70+
auto st = reserved_stack(begin_node);
6771
if (rgn_size == 0) {
6872
prev.clear_node();
6973
return true;
7074
}
71-
ReservedMemoryRegion rmr((address)begin_node.position(), rgn_size, st, begin_node.out_tag());
72-
if (!func(rmr)) {
75+
VirtualMemoryRegion rgn((address)begin_node.position(), rgn_size, st, begin_node.out_tag());
76+
if (!func(rgn)) {
7377
return false;
7478
}
7579
rgn_size = 0;

src/hotspot/share/nmt/virtualMemoryTracker.cpp

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2013, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -193,14 +193,14 @@ bool VirtualMemoryTracker::Instance::print_containing_region(const void* p, outp
193193
}
194194

195195
bool VirtualMemoryTracker::print_containing_region(const void* p, outputStream* st) {
196-
ReservedMemoryRegion rmr = tree()->find_reserved_region((address)p);
197-
if (!rmr.contain_address((address)p)) {
196+
VirtualMemoryRegion rgn = tree()->find_reserved_region((address)p);
197+
if (!rgn.is_valid() || !rgn.contain_address((address)p)) {
198198
return false;
199199
}
200200
st->print_cr(PTR_FORMAT " in mmap'd memory region [" PTR_FORMAT " - " PTR_FORMAT "], tag %s",
201-
p2i(p), p2i(rmr.base()), p2i(rmr.end()), NMTUtil::tag_to_enum_name(rmr.mem_tag()));
201+
p2i(p), p2i(rgn.base()), p2i(rgn.end()), NMTUtil::tag_to_enum_name(rgn.mem_tag()));
202202
if (MemTracker::tracking_level() == NMT_detail) {
203-
rmr.call_stack()->print_on(st);
203+
rgn.reserved_call_stack()->print_on(st);
204204
}
205205
st->cr();
206206
return true;
@@ -213,7 +213,7 @@ bool VirtualMemoryTracker::Instance::walk_virtual_memory(VirtualMemoryWalker* wa
213213

214214
bool VirtualMemoryTracker::walk_virtual_memory(VirtualMemoryWalker* walker) {
215215
bool ret = true;
216-
tree()->visit_reserved_regions([&](ReservedMemoryRegion& rgn) {
216+
tree()->visit_reserved_regions([&](VirtualMemoryRegion& rgn) {
217217
if (!walker->do_allocation_site(&rgn)) {
218218
ret = false;
219219
return false;
@@ -223,29 +223,29 @@ bool VirtualMemoryTracker::walk_virtual_memory(VirtualMemoryWalker* walker) {
223223
return ret;
224224
}
225225

226-
size_t VirtualMemoryTracker::committed_size(const ReservedMemoryRegion* rmr) {
226+
size_t VirtualMemoryTracker::committed_size(const VirtualMemoryRegion* rgn) {
227227
size_t result = 0;
228-
tree()->visit_committed_regions(*rmr, [&](CommittedMemoryRegion& crgn) {
228+
tree()->visit_committed_regions(*rgn, [&](VirtualMemoryRegion& crgn) {
229229
result += crgn.size();
230230
return true;
231231
});
232232
return result;
233233
}
234234

235-
size_t VirtualMemoryTracker::Instance::committed_size(const ReservedMemoryRegion* rmr) {
235+
size_t VirtualMemoryTracker::Instance::committed_size(const VirtualMemoryRegion* rgn) {
236236
assert(_tracker != nullptr, "Sanity check");
237-
return _tracker->committed_size(rmr);
237+
return _tracker->committed_size(rgn);
238238
}
239239

240-
address VirtualMemoryTracker::Instance::thread_stack_uncommitted_bottom(const ReservedMemoryRegion* rmr) {
240+
address VirtualMemoryTracker::Instance::thread_stack_uncommitted_bottom(const VirtualMemoryRegion* rgn) {
241241
assert(_tracker != nullptr, "Sanity check");
242-
return _tracker->thread_stack_uncommitted_bottom(rmr);
242+
return _tracker->thread_stack_uncommitted_bottom(rgn);
243243
}
244244

245-
address VirtualMemoryTracker::thread_stack_uncommitted_bottom(const ReservedMemoryRegion* rmr) {
246-
address bottom = rmr->base();
247-
address top = rmr->end();
248-
tree()->visit_committed_regions(*rmr, [&](CommittedMemoryRegion& crgn) {
245+
address VirtualMemoryTracker::thread_stack_uncommitted_bottom(const VirtualMemoryRegion* rgn) {
246+
address bottom = rgn->base();
247+
address top = rgn->end();
248+
tree()->visit_committed_regions(*rgn, [&](VirtualMemoryRegion& crgn) {
249249
address committed_top = crgn.base() + crgn.size();
250250
if (committed_top < top) {
251251
// committed stack guard pages, skip them
@@ -299,7 +299,7 @@ class SnapshotThreadStackWalker : public VirtualMemoryWalker {
299299
public:
300300
SnapshotThreadStackWalker() {}
301301

302-
bool do_allocation_site(const ReservedMemoryRegion* rgn) {
302+
bool do_allocation_site(const VirtualMemoryRegion* rgn) {
303303
if (MemTracker::NmtVirtualMemoryLocker::is_safe_to_use()) {
304304
assert_lock_strong(NmtVirtualMemory_lock);
305305
}
@@ -340,19 +340,19 @@ void VirtualMemoryTracker::Instance::snapshot_thread_stacks() {
340340
walk_virtual_memory(&walker);
341341
}
342342

343-
ReservedMemoryRegion RegionsTree::find_reserved_region(address addr) {
344-
ReservedMemoryRegion rmr;
345-
auto contain_region = [&](ReservedMemoryRegion& region_in_tree) {
343+
VirtualMemoryRegion RegionsTree::find_reserved_region(address addr) {
344+
VirtualMemoryRegion rgn;
345+
auto contain_region = [&](VirtualMemoryRegion& region_in_tree) {
346346
if (region_in_tree.contain_address(addr)) {
347-
rmr = region_in_tree;
347+
rgn = region_in_tree;
348348
return false;
349349
}
350350
return true;
351351
};
352352
visit_reserved_regions(contain_region);
353-
return rmr;
353+
return rgn;
354354
}
355355

356-
bool CommittedMemoryRegion::equals(const ReservedMemoryRegion& rmr) const {
357-
return size() == rmr.size() && call_stack()->equals(*(rmr.call_stack()));
356+
bool VirtualMemoryRegion::equals_including_stacks(const VirtualMemoryRegion& rgn) const {
357+
return size() == rgn.size() && committed_call_stack()->equals(*(rgn.reserved_call_stack()));
358358
}

0 commit comments

Comments
 (0)