Skip to content

Commit fb70325

Browse files
committed
8338583: NMT: Malloc overhead is calculated incorrectly
Reviewed-by: azafari, yan, gziemski
1 parent 083b980 commit fb70325

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

src/hotspot/share/nmt/mallocHeader.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ class MallocHeader {
127127

128128
inline MallocHeader(size_t size, MemTag mem_tag, uint32_t mst_marker);
129129

130+
inline static size_t malloc_overhead() { return sizeof(MallocHeader) + sizeof(uint16_t); }
130131
inline size_t size() const { return _size; }
131132
inline MemTag mem_tag() const { return _mem_tag; }
132133
inline uint32_t mst_marker() const { return _mst_marker; }

src/hotspot/share/nmt/mallocTracker.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ class MallocMemorySnapshot {
166166
}
167167

168168
inline size_t malloc_overhead() const {
169-
return _all_mallocs.count() * sizeof(MallocHeader);
169+
return _all_mallocs.count() * MallocHeader::malloc_overhead();
170170
}
171171

172172
// Total malloc invocation count
@@ -269,7 +269,7 @@ class MallocTracker : AllStatic {
269269

270270
// The overhead that is incurred by switching on NMT (we need, per malloc allocation,
271271
// space for header and 16-bit footer)
272-
static const size_t overhead_per_malloc = sizeof(MallocHeader) + sizeof(uint16_t);
272+
static inline size_t overhead_per_malloc() { return MallocHeader::malloc_overhead(); }
273273

274274
// Parameter name convention:
275275
// memblock : the beginning address for user data

src/hotspot/share/nmt/memTracker.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class MemTracker : AllStatic {
7272

7373
// Per-malloc overhead incurred by NMT, depending on the current NMT level
7474
static size_t overhead_per_malloc() {
75-
return enabled() ? MallocTracker::overhead_per_malloc : 0;
75+
return enabled() ? MallocTracker::overhead_per_malloc() : 0;
7676
}
7777

7878
static inline void* record_malloc(void* mem_base, size_t size, MemTag mem_tag,

0 commit comments

Comments
 (0)