Skip to content

Commit a7f6016

Browse files
committed
8320370: NMT: Change MallocMemorySnapshot to simplify code.
Reviewed-by: stuefe, gziemski, stefank
1 parent 58530f4 commit a7f6016

File tree

5 files changed

+7
-19
lines changed

5 files changed

+7
-19
lines changed

src/hotspot/share/nmt/mallocTracker.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
#include "utilities/ostream.hpp"
4444
#include "utilities/vmError.hpp"
4545

46-
size_t MallocMemorySummary::_snapshot[CALC_OBJ_SIZE_IN_TYPE(MallocMemorySnapshot, size_t)];
46+
MallocMemorySnapshot MallocMemorySummary::_snapshot;
4747

4848
void MemoryCounter::update_peak(size_t size, size_t cnt) {
4949
size_t peak_sz = peak_size();
@@ -78,9 +78,7 @@ void MallocMemorySnapshot::make_adjustment() {
7878
}
7979

8080
void MallocMemorySummary::initialize() {
81-
assert(sizeof(_snapshot) >= sizeof(MallocMemorySnapshot), "Sanity Check");
8281
// Uses placement new operator to initialize static area.
83-
::new ((void*)_snapshot)MallocMemorySnapshot();
8482
MallocLimitHandler::initialize(MallocLimit);
8583
}
8684

src/hotspot/share/nmt/mallocTracker.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class MallocMemorySummary;
140140

141141
// A snapshot of malloc'd memory, includes malloc memory
142142
// usage by types and memory used by tracking itself.
143-
class MallocMemorySnapshot : public ResourceObj {
143+
class MallocMemorySnapshot {
144144
friend class MallocMemorySummary;
145145

146146
private:
@@ -198,7 +198,7 @@ class MallocMemorySnapshot : public ResourceObj {
198198
class MallocMemorySummary : AllStatic {
199199
private:
200200
// Reserve memory for placement of MallocMemorySnapshot object
201-
static size_t _snapshot[CALC_OBJ_SIZE_IN_TYPE(MallocMemorySnapshot, size_t)];
201+
static MallocMemorySnapshot _snapshot;
202202
static bool _have_limits;
203203

204204
// Called when a total limit break was detected.
@@ -245,7 +245,7 @@ class MallocMemorySummary : AllStatic {
245245
}
246246

247247
static MallocMemorySnapshot* as_snapshot() {
248-
return (MallocMemorySnapshot*)_snapshot;
248+
return &_snapshot;
249249
}
250250

251251
// MallocLimit: returns true if allocating s bytes on f would trigger

src/hotspot/share/nmt/nmtCommon.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
#include "utilities/align.hpp"
3232
#include "utilities/globalDefinitions.hpp"
3333

34-
#define CALC_OBJ_SIZE_IN_TYPE(obj, type) (align_up(sizeof(obj), sizeof(type))/sizeof(type))
35-
3634
// Native memory tracking level
3735
//
3836
// The meaning of the different states:

src/hotspot/share/nmt/virtualMemoryTracker.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#include "runtime/threadCritical.hpp"
3333
#include "utilities/ostream.hpp"
3434

35-
size_t VirtualMemorySummary::_snapshot[CALC_OBJ_SIZE_IN_TYPE(VirtualMemorySnapshot, size_t)];
35+
VirtualMemorySnapshot VirtualMemorySummary::_snapshot;
3636

3737
void VirtualMemory::update_peak(size_t size) {
3838
size_t peak_sz = peak_size();
@@ -46,12 +46,6 @@ void VirtualMemory::update_peak(size_t size) {
4646
}
4747
}
4848

49-
void VirtualMemorySummary::initialize() {
50-
assert(sizeof(_snapshot) >= sizeof(VirtualMemorySnapshot), "Sanity Check");
51-
// Use placement operator new to initialize static data area.
52-
::new ((void*)_snapshot) VirtualMemorySnapshot();
53-
}
54-
5549
void VirtualMemorySummary::snapshot(VirtualMemorySnapshot* s) {
5650
// Only if thread stack is backed by virtual memory
5751
if (ThreadStackTracker::track_as_vm()) {
@@ -334,7 +328,6 @@ address ReservedMemoryRegion::thread_stack_uncommitted_bottom() const {
334328
bool VirtualMemoryTracker::initialize(NMT_TrackingLevel level) {
335329
assert(_reserved_regions == nullptr, "only call once");
336330
if (level >= NMT_summary) {
337-
VirtualMemorySummary::initialize();
338331
_reserved_regions = new (std::nothrow, mtNMT)
339332
SortedLinkedList<ReservedMemoryRegion, compare_reserved_region_base>();
340333
return (_reserved_regions != nullptr);

src/hotspot/share/nmt/virtualMemoryTracker.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ class VirtualMemorySnapshot : public ResourceObj {
132132

133133
class VirtualMemorySummary : AllStatic {
134134
public:
135-
static void initialize();
136135

137136
static inline void record_reserved_memory(size_t size, MEMFLAGS flag) {
138137
as_snapshot()->by_type(flag)->reserve_memory(size);
@@ -167,11 +166,11 @@ class VirtualMemorySummary : AllStatic {
167166
static void snapshot(VirtualMemorySnapshot* s);
168167

169168
static VirtualMemorySnapshot* as_snapshot() {
170-
return (VirtualMemorySnapshot*)_snapshot;
169+
return &_snapshot;
171170
}
172171

173172
private:
174-
static size_t _snapshot[CALC_OBJ_SIZE_IN_TYPE(VirtualMemorySnapshot, size_t)];
173+
static VirtualMemorySnapshot _snapshot;
175174
};
176175

177176

0 commit comments

Comments
 (0)