Skip to content

Commit 4066f33

Browse files
author
Afshin Zafari
committed
8350565: NMT: remaining memory flag/type to be replaced with memory tag
Reviewed-by: gziemski, jsjolen
1 parent 7314efc commit 4066f33

17 files changed

+77
-77
lines changed

src/hotspot/share/nmt/mallocTracker.hpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2025, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2021, 2023 SAP SE. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
@@ -145,7 +145,7 @@ class MallocMemory {
145145
class MallocMemorySummary;
146146

147147
// A snapshot of malloc'd memory, includes malloc memory
148-
// usage by types and memory used by tracking itself.
148+
// usage by tags and memory used by tracking itself.
149149
class MallocMemorySnapshot {
150150
friend class MallocMemorySummary;
151151

@@ -155,12 +155,12 @@ class MallocMemorySnapshot {
155155

156156

157157
public:
158-
inline MallocMemory* by_type(MemTag mem_tag) {
158+
inline MallocMemory* by_tag(MemTag mem_tag) {
159159
int index = NMTUtil::tag_to_index(mem_tag);
160160
return &_malloc[index];
161161
}
162162

163-
inline const MallocMemory* by_type(MemTag mem_tag) const {
163+
inline const MallocMemory* by_tag(MemTag mem_tag) const {
164164
int index = NMTUtil::tag_to_index(mem_tag);
165165
return &_malloc[index];
166166
}
@@ -220,25 +220,25 @@ class MallocMemorySummary : AllStatic {
220220
static void initialize();
221221

222222
static inline void record_malloc(size_t size, MemTag mem_tag) {
223-
as_snapshot()->by_type(mem_tag)->record_malloc(size);
223+
as_snapshot()->by_tag(mem_tag)->record_malloc(size);
224224
as_snapshot()->_all_mallocs.allocate(size);
225225
}
226226

227227
static inline void record_free(size_t size, MemTag mem_tag) {
228-
as_snapshot()->by_type(mem_tag)->record_free(size);
228+
as_snapshot()->by_tag(mem_tag)->record_free(size);
229229
as_snapshot()->_all_mallocs.deallocate(size);
230230
}
231231

232232
static inline void record_new_arena(MemTag mem_tag) {
233-
as_snapshot()->by_type(mem_tag)->record_new_arena();
233+
as_snapshot()->by_tag(mem_tag)->record_new_arena();
234234
}
235235

236236
static inline void record_arena_free(MemTag mem_tag) {
237-
as_snapshot()->by_type(mem_tag)->record_arena_free();
237+
as_snapshot()->by_tag(mem_tag)->record_arena_free();
238238
}
239239

240240
static inline void record_arena_size_change(ssize_t size, MemTag mem_tag) {
241-
as_snapshot()->by_type(mem_tag)->record_arena_size_change(size);
241+
as_snapshot()->by_tag(mem_tag)->record_arena_size_change(size);
242242
}
243243

244244
static void snapshot(MallocMemorySnapshot* s) {

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (c) 2023 SAP SE. All rights reserved.
3-
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
3+
* Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
66
* This code is free software; you can redistribute it and/or modify it
@@ -52,7 +52,7 @@ inline bool MallocMemorySummary::check_exceeds_limit(size_t s, MemTag mem_tag) {
5252
// Category Limit?
5353
l = MallocLimitHandler::category_limit(mem_tag);
5454
if (l->sz > 0) {
55-
const MallocMemory* mm = as_snapshot()->by_type(mem_tag);
55+
const MallocMemory* mm = as_snapshot()->by_tag(mem_tag);
5656
size_t so_far = mm->malloc_size() + mm->arena_size();
5757
if ((so_far + s) > l->sz) {
5858
return category_limit_reached(mem_tag, s, so_far, l);

src/hotspot/share/nmt/memBaseline.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ int compare_malloc_site(const MallocSite& s1, const MallocSite& s2) {
6161
}
6262

6363
// Sort into allocation site addresses and memory tag order for baseline comparison
64-
int compare_malloc_site_and_type(const MallocSite& s1, const MallocSite& s2) {
64+
int compare_malloc_site_and_tag(const MallocSite& s1, const MallocSite& s2) {
6565
int res = compare_malloc_site(s1, s2);
6666
if (res == 0) {
6767
res = (int)(NMTUtil::tag_to_index(s1.mem_tag()) - NMTUtil::tag_to_index(s2.mem_tag()));
@@ -231,8 +231,8 @@ MallocSiteIterator MemBaseline::malloc_sites(SortingOrder order) {
231231
case by_site:
232232
malloc_sites_to_allocation_site_order();
233233
break;
234-
case by_site_and_type:
235-
malloc_sites_to_allocation_site_and_type_order();
234+
case by_site_and_tag:
235+
malloc_sites_to_allocation_site_and_tag_order();
236236
break;
237237
case by_address:
238238
default:
@@ -272,7 +272,7 @@ void MemBaseline::malloc_sites_to_size_order() {
272272
}
273273

274274
void MemBaseline::malloc_sites_to_allocation_site_order() {
275-
if (_malloc_sites_order != by_site && _malloc_sites_order != by_site_and_type) {
275+
if (_malloc_sites_order != by_site && _malloc_sites_order != by_site_and_tag) {
276276
SortedLinkedList<MallocSite, compare_malloc_site> tmp;
277277
// Add malloc sites to sorted linked list to sort into site (address) order
278278
tmp.move(&_malloc_sites);
@@ -282,14 +282,14 @@ void MemBaseline::malloc_sites_to_allocation_site_order() {
282282
}
283283
}
284284

285-
void MemBaseline::malloc_sites_to_allocation_site_and_type_order() {
286-
if (_malloc_sites_order != by_site_and_type) {
287-
SortedLinkedList<MallocSite, compare_malloc_site_and_type> tmp;
285+
void MemBaseline::malloc_sites_to_allocation_site_and_tag_order() {
286+
if (_malloc_sites_order != by_site_and_tag) {
287+
SortedLinkedList<MallocSite, compare_malloc_site_and_tag> tmp;
288288
// Add malloc sites to sorted linked list to sort into site (address) order
289289
tmp.move(&_malloc_sites);
290290
_malloc_sites.set_head(tmp.head());
291291
tmp.set_head(nullptr);
292-
_malloc_sites_order = by_site_and_type;
292+
_malloc_sites_order = by_site_and_tag;
293293
}
294294
}
295295

src/hotspot/share/nmt/memBaseline.hpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2025, 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
@@ -53,7 +53,7 @@ class MemBaseline {
5353
by_address, // by memory address
5454
by_size, // by memory size
5555
by_site, // by call site where the memory is allocated from
56-
by_site_and_type // by call site and memory tag
56+
by_site_and_tag // by call site and memory tag
5757
};
5858

5959
private:
@@ -146,12 +146,12 @@ class MemBaseline {
146146

147147
MallocMemory* malloc_memory(MemTag mem_tag) {
148148
assert(baseline_type() != Not_baselined, "Not yet baselined");
149-
return _malloc_memory_snapshot.by_type(mem_tag);
149+
return _malloc_memory_snapshot.by_tag(mem_tag);
150150
}
151151

152152
VirtualMemory* virtual_memory(MemTag mem_tag) {
153153
assert(baseline_type() != Not_baselined, "Not yet baselined");
154-
return _virtual_memory_snapshot.by_type(mem_tag);
154+
return _virtual_memory_snapshot.by_tag(mem_tag);
155155
}
156156

157157

@@ -204,7 +204,7 @@ class MemBaseline {
204204
// Sort allocation sites in call site address order
205205
void malloc_sites_to_allocation_site_order();
206206
// Sort allocation sites in call site address and memory tag order
207-
void malloc_sites_to_allocation_site_and_type_order();
207+
void malloc_sites_to_allocation_site_and_tag_order();
208208

209209
// Sort allocation sites in reserved size order
210210
void virtual_memory_sites_to_size_order();

src/hotspot/share/nmt/memReporter.cpp

+12-12
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void MemReporterBase::print_malloc(const MemoryCounter* c, MemTag mem_tag) const
7979
const size_t count = c->count();
8080

8181
if (mem_tag != mtNone) {
82-
out->print("(%s%zu%s type=%s", alloc_type,
82+
out->print("(%s%zu%s tag=%s", alloc_type,
8383
amount_in_current_scale(amount), scale, NMTUtil::tag_to_name(mem_tag));
8484
} else {
8585
out->print("(%s%zu%s", alloc_type,
@@ -181,14 +181,14 @@ void MemSummaryReporter::report() {
181181
MemTag mem_tag = NMTUtil::index_to_tag(index);
182182
// thread stack is reported as part of thread category
183183
if (mem_tag == mtThreadStack) continue;
184-
MallocMemory* malloc_memory = _malloc_snapshot->by_type(mem_tag);
185-
VirtualMemory* virtual_memory = _vm_snapshot->by_type(mem_tag);
184+
MallocMemory* malloc_memory = _malloc_snapshot->by_tag(mem_tag);
185+
VirtualMemory* virtual_memory = _vm_snapshot->by_tag(mem_tag);
186186

187-
report_summary_of_type(mem_tag, malloc_memory, virtual_memory);
187+
report_summary_of_tag(mem_tag, malloc_memory, virtual_memory);
188188
}
189189
}
190190

191-
void MemSummaryReporter::report_summary_of_type(MemTag mem_tag,
191+
void MemSummaryReporter::report_summary_of_tag(MemTag mem_tag,
192192
MallocMemory* malloc_memory, VirtualMemory* virtual_memory) {
193193

194194
size_t reserved_amount = reserved_total (malloc_memory, virtual_memory);
@@ -197,7 +197,7 @@ void MemSummaryReporter::report_summary_of_type(MemTag mem_tag,
197197
// Count thread's native stack in "Thread" category
198198
if (mem_tag == mtThread) {
199199
const VirtualMemory* thread_stack_usage =
200-
(const VirtualMemory*)_vm_snapshot->by_type(mtThreadStack);
200+
(const VirtualMemory*)_vm_snapshot->by_tag(mtThreadStack);
201201
reserved_amount += thread_stack_usage->reserved();
202202
committed_amount += thread_stack_usage->committed();
203203
} else if (mem_tag == mtNMT) {
@@ -239,7 +239,7 @@ void MemSummaryReporter::report_summary_of_type(MemTag mem_tag,
239239
_instance_class_count, _array_class_count);
240240
} else if (mem_tag == mtThread) {
241241
const VirtualMemory* thread_stack_usage =
242-
_vm_snapshot->by_type(mtThreadStack);
242+
_vm_snapshot->by_tag(mtThreadStack);
243243
// report thread count
244244
out->print_cr("(threads #%zu)", ThreadStackTracker::thread_count());
245245
out->print("(stack: ");
@@ -380,7 +380,7 @@ int MemDetailReporter::report_virtual_memory_allocation_sites() {
380380
print_total(virtual_memory_site->reserved(), virtual_memory_site->committed());
381381
const MemTag mem_tag = virtual_memory_site->mem_tag();
382382
if (mem_tag != mtNone) {
383-
out->print(" Type=%s", NMTUtil::tag_to_name(mem_tag));
383+
out->print(" Tag=%s", NMTUtil::tag_to_name(mem_tag));
384384
}
385385
out->print_cr(")");
386386
)
@@ -524,7 +524,7 @@ void MemSummaryDiffReporter::report_diff() {
524524
MemTag mem_tag = NMTUtil::index_to_tag(index);
525525
// thread stack is reported as part of thread category
526526
if (mem_tag == mtThreadStack) continue;
527-
diff_summary_of_type(mem_tag,
527+
diff_summary_of_tag(mem_tag,
528528
_early_baseline.malloc_memory(mem_tag),
529529
_early_baseline.virtual_memory(mem_tag),
530530
_early_baseline.metaspace_stats(),
@@ -594,7 +594,7 @@ void MemSummaryDiffReporter::print_virtual_memory_diff(size_t current_reserved,
594594
}
595595

596596

597-
void MemSummaryDiffReporter::diff_summary_of_type(MemTag mem_tag,
597+
void MemSummaryDiffReporter::diff_summary_of_tag(MemTag mem_tag,
598598
const MallocMemory* early_malloc, const VirtualMemory* early_vm,
599599
const MetaspaceCombinedStats& early_ms,
600600
const MallocMemory* current_malloc, const VirtualMemory* current_vm,
@@ -795,8 +795,8 @@ void MemDetailDiffReporter::report_diff() {
795795
}
796796

797797
void MemDetailDiffReporter::diff_malloc_sites() const {
798-
MallocSiteIterator early_itr = _early_baseline.malloc_sites(MemBaseline::by_site_and_type);
799-
MallocSiteIterator current_itr = _current_baseline.malloc_sites(MemBaseline::by_site_and_type);
798+
MallocSiteIterator early_itr = _early_baseline.malloc_sites(MemBaseline::by_site_and_tag);
799+
MallocSiteIterator current_itr = _current_baseline.malloc_sites(MemBaseline::by_site_and_tag);
800800

801801
const MallocSite* early_site = early_itr.next();
802802
const MallocSite* current_site = current_itr.next();

src/hotspot/share/nmt/memReporter.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2025, 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
@@ -139,7 +139,7 @@ class MemSummaryReporter : public MemReporterBase {
139139
virtual void report();
140140
private:
141141
// Report summary for each memory tag
142-
void report_summary_of_type(MemTag mem_tag, MallocMemory* malloc_memory,
142+
void report_summary_of_tag(MemTag mem_tag, MallocMemory* malloc_memory,
143143
VirtualMemory* virtual_memory);
144144

145145
void report_metadata(Metaspace::MetadataType type) const;
@@ -204,7 +204,7 @@ class MemSummaryDiffReporter : public MemReporterBase {
204204

205205
private:
206206
// report the comparison of each mem_tag
207-
void diff_summary_of_type(MemTag mem_tag,
207+
void diff_summary_of_tag(MemTag mem_tag,
208208
const MallocMemory* early_malloc, const VirtualMemory* early_vm,
209209
const MetaspaceCombinedStats& early_ms,
210210
const MallocMemory* current_malloc, const VirtualMemory* current_vm,

src/hotspot/share/nmt/memTracker.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void MemTracker::initialize() {
6262
assert(level == NMT_off || level == NMT_summary || level == NMT_detail,
6363
"Invalid setting for NativeMemoryTracking (%s)", NativeMemoryTracking);
6464

65-
// Memory type is encoded into tracking header as a byte field,
65+
// Memory tag is encoded into tracking header as a byte field,
6666
// make sure that we don't overflow it.
6767
STATIC_ASSERT(mt_number_of_tags <= max_jubyte);
6868

src/hotspot/share/nmt/memTracker.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2013, 2025, 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
@@ -210,7 +210,7 @@ class MemTracker : AllStatic {
210210
// be fully uncommitted.
211211
//
212212
// The two new memory regions will be both registered under stack and
213-
// memory flags of the original region.
213+
// memory tags of the original region.
214214
static inline void record_virtual_memory_split_reserved(void* addr, size_t size, size_t split, MemTag mem_tag, MemTag split_tag) {
215215
assert_post_init();
216216
if (!enabled()) return;
@@ -225,7 +225,7 @@ class MemTracker : AllStatic {
225225
if (!enabled()) return;
226226
if (addr != nullptr) {
227227
NmtVirtualMemoryLocker nvml;
228-
VirtualMemoryTracker::set_reserved_region_type((address)addr, mem_tag);
228+
VirtualMemoryTracker::set_reserved_region_tag((address)addr, mem_tag);
229229
}
230230
}
231231

src/hotspot/share/nmt/memoryFileTracker.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void MemoryFileTracker::allocate_memory(MemoryFile* file, size_t offset,
4444
VMATree::RegionData regiondata(sidx, mem_tag);
4545
VMATree::SummaryDiff diff = file->_tree.commit_mapping(offset, size, regiondata);
4646
for (int i = 0; i < mt_number_of_tags; i++) {
47-
VirtualMemory* summary = file->_summary.by_type(NMTUtil::index_to_tag(i));
47+
VirtualMemory* summary = file->_summary.by_tag(NMTUtil::index_to_tag(i));
4848
summary->reserve_memory(diff.tag[i].commit);
4949
summary->commit_memory(diff.tag[i].commit);
5050
}
@@ -53,7 +53,7 @@ void MemoryFileTracker::allocate_memory(MemoryFile* file, size_t offset,
5353
void MemoryFileTracker::free_memory(MemoryFile* file, size_t offset, size_t size) {
5454
VMATree::SummaryDiff diff = file->_tree.release_mapping(offset, size);
5555
for (int i = 0; i < mt_number_of_tags; i++) {
56-
VirtualMemory* summary = file->_summary.by_type(NMTUtil::index_to_tag(i));
56+
VirtualMemory* summary = file->_summary.by_tag(NMTUtil::index_to_tag(i));
5757
summary->reserve_memory(diff.tag[i].commit);
5858
summary->commit_memory(diff.tag[i].commit);
5959
}
@@ -176,7 +176,7 @@ const GrowableArrayCHeap<MemoryFileTracker::MemoryFile*, mtNMT>& MemoryFileTrack
176176

177177
void MemoryFileTracker::summary_snapshot(VirtualMemorySnapshot* snapshot) const {
178178
iterate_summary([&](MemTag tag, const VirtualMemory* current) {
179-
VirtualMemory* snap = snapshot->by_type(tag);
179+
VirtualMemory* snap = snapshot->by_tag(tag);
180180
// Only account the committed memory.
181181
snap->commit_memory(current->committed());
182182
});

src/hotspot/share/nmt/memoryFileTracker.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2024, 2025, 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
@@ -78,7 +78,7 @@ class MemoryFileTracker {
7878
for (int d = 0; d < _files.length(); d++) {
7979
const MemoryFile* file = _files.at(d);
8080
for (int i = 0; i < mt_number_of_tags; i++) {
81-
f(NMTUtil::index_to_tag(i), file->_summary.by_type(NMTUtil::index_to_tag(i)));
81+
f(NMTUtil::index_to_tag(i), file->_summary.by_tag(NMTUtil::index_to_tag(i)));
8282
}
8383
}
8484
}

src/hotspot/share/nmt/nmtCommon.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ STATIC_ASSERT(NMT_off > NMT_unknown);
2929
STATIC_ASSERT(NMT_summary > NMT_off);
3030
STATIC_ASSERT(NMT_detail > NMT_summary);
3131

32-
#define MEMORY_TAG_DECLARE_NAME(type, human_readable) \
33-
{ #type, human_readable },
32+
#define MEMORY_TAG_DECLARE_NAME(tag, human_readable) \
33+
{ #tag, human_readable },
3434

3535
NMTUtil::S NMTUtil::_strings[] = {
3636
MEMORY_TAG_DO(MEMORY_TAG_DECLARE_NAME)

src/hotspot/share/nmt/nmtCommon.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2025, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2021, 2023 SAP SE. All rights reserved.
44
55
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
@@ -88,7 +88,7 @@ class NMTUtil : AllStatic {
8888

8989
// Map memory tag to index
9090
static inline int tag_to_index(MemTag mem_tag) {
91-
assert(tag_is_valid(mem_tag), "Invalid type (%u)", (unsigned)mem_tag);
91+
assert(tag_is_valid(mem_tag), "Invalid tag (%u)", (unsigned)mem_tag);
9292
return static_cast<int>(mem_tag);
9393
}
9494

@@ -104,7 +104,7 @@ class NMTUtil : AllStatic {
104104

105105
// Map an index to memory tag
106106
static MemTag index_to_tag(int index) {
107-
assert(tag_index_is_valid(index), "Invalid type index (%d)", index);
107+
assert(tag_index_is_valid(index), "Invalid tag index (%d)", index);
108108
return static_cast<MemTag>(index);
109109
}
110110

0 commit comments

Comments
 (0)