Skip to content

Commit 153de5a

Browse files
committed
8320370: NMT: Change MallocMemorySnapshot to simplify code.
Reviewed-by: stuefe Backport-of: a7f60164063bdf95437326e7550fd65ff91b5566
1 parent fa874b3 commit 153de5a

File tree

5 files changed

+7
-19
lines changed

5 files changed

+7
-19
lines changed

src/hotspot/share/services/mallocTracker.cpp

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

47-
size_t MallocMemorySummary::_snapshot[CALC_OBJ_SIZE_IN_TYPE(MallocMemorySnapshot, size_t)];
47+
MallocMemorySnapshot MallocMemorySummary::_snapshot;
4848

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

8181
void MallocMemorySummary::initialize() {
82-
assert(sizeof(_snapshot) >= sizeof(MallocMemorySnapshot), "Sanity Check");
8382
// Uses placement new operator to initialize static area.
84-
::new ((void*)_snapshot)MallocMemorySnapshot();
8583
MallocLimitHandler::initialize(MallocLimit);
8684
}
8785

src/hotspot/share/services/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/services/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/services/virtualMemoryTracker.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#include "services/virtualMemoryTracker.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/services/virtualMemoryTracker.hpp

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

135135
class VirtualMemorySummary : AllStatic {
136136
public:
137-
static void initialize();
138137

139138
static inline void record_reserved_memory(size_t size, MEMFLAGS flag) {
140139
as_snapshot()->by_type(flag)->reserve_memory(size);
@@ -169,11 +168,11 @@ class VirtualMemorySummary : AllStatic {
169168
static void snapshot(VirtualMemorySnapshot* s);
170169

171170
static VirtualMemorySnapshot* as_snapshot() {
172-
return (VirtualMemorySnapshot*)_snapshot;
171+
return &_snapshot;
173172
}
174173

175174
private:
176-
static size_t _snapshot[CALC_OBJ_SIZE_IN_TYPE(VirtualMemorySnapshot, size_t)];
175+
static VirtualMemorySnapshot _snapshot;
177176
};
178177

179178

0 commit comments

Comments
 (0)