diff --git a/src/hotspot/share/nmt/mallocTracker.cpp b/src/hotspot/share/nmt/mallocTracker.cpp index ea14ddc1e2051..3d1816ab630fc 100644 --- a/src/hotspot/share/nmt/mallocTracker.cpp +++ b/src/hotspot/share/nmt/mallocTracker.cpp @@ -43,7 +43,7 @@ #include "utilities/ostream.hpp" #include "utilities/vmError.hpp" -size_t MallocMemorySummary::_snapshot[CALC_OBJ_SIZE_IN_TYPE(MallocMemorySnapshot, size_t)]; +MallocMemorySnapshot MallocMemorySummary::_snapshot; void MemoryCounter::update_peak(size_t size, size_t cnt) { size_t peak_sz = peak_size(); @@ -78,9 +78,7 @@ void MallocMemorySnapshot::make_adjustment() { } void MallocMemorySummary::initialize() { - assert(sizeof(_snapshot) >= sizeof(MallocMemorySnapshot), "Sanity Check"); // Uses placement new operator to initialize static area. - ::new ((void*)_snapshot)MallocMemorySnapshot(); MallocLimitHandler::initialize(MallocLimit); } diff --git a/src/hotspot/share/nmt/mallocTracker.hpp b/src/hotspot/share/nmt/mallocTracker.hpp index ae56d31d786d1..964acb6d201f7 100644 --- a/src/hotspot/share/nmt/mallocTracker.hpp +++ b/src/hotspot/share/nmt/mallocTracker.hpp @@ -140,7 +140,7 @@ class MallocMemorySummary; // A snapshot of malloc'd memory, includes malloc memory // usage by types and memory used by tracking itself. -class MallocMemorySnapshot : public ResourceObj { +class MallocMemorySnapshot { friend class MallocMemorySummary; private: @@ -198,7 +198,7 @@ class MallocMemorySnapshot : public ResourceObj { class MallocMemorySummary : AllStatic { private: // Reserve memory for placement of MallocMemorySnapshot object - static size_t _snapshot[CALC_OBJ_SIZE_IN_TYPE(MallocMemorySnapshot, size_t)]; + static MallocMemorySnapshot _snapshot; static bool _have_limits; // Called when a total limit break was detected. @@ -245,7 +245,7 @@ class MallocMemorySummary : AllStatic { } static MallocMemorySnapshot* as_snapshot() { - return (MallocMemorySnapshot*)_snapshot; + return &_snapshot; } // MallocLimit: returns true if allocating s bytes on f would trigger diff --git a/src/hotspot/share/nmt/nmtCommon.hpp b/src/hotspot/share/nmt/nmtCommon.hpp index 4dafaed04ce0e..c6d1bcddf5e4e 100644 --- a/src/hotspot/share/nmt/nmtCommon.hpp +++ b/src/hotspot/share/nmt/nmtCommon.hpp @@ -31,8 +31,6 @@ #include "utilities/align.hpp" #include "utilities/globalDefinitions.hpp" -#define CALC_OBJ_SIZE_IN_TYPE(obj, type) (align_up(sizeof(obj), sizeof(type))/sizeof(type)) - // Native memory tracking level // // The meaning of the different states: diff --git a/src/hotspot/share/nmt/virtualMemoryTracker.cpp b/src/hotspot/share/nmt/virtualMemoryTracker.cpp index 5bb9072666064..16fbaa30276ef 100644 --- a/src/hotspot/share/nmt/virtualMemoryTracker.cpp +++ b/src/hotspot/share/nmt/virtualMemoryTracker.cpp @@ -32,7 +32,7 @@ #include "runtime/threadCritical.hpp" #include "utilities/ostream.hpp" -size_t VirtualMemorySummary::_snapshot[CALC_OBJ_SIZE_IN_TYPE(VirtualMemorySnapshot, size_t)]; +VirtualMemorySnapshot VirtualMemorySummary::_snapshot; void VirtualMemory::update_peak(size_t size) { size_t peak_sz = peak_size(); @@ -46,12 +46,6 @@ void VirtualMemory::update_peak(size_t size) { } } -void VirtualMemorySummary::initialize() { - assert(sizeof(_snapshot) >= sizeof(VirtualMemorySnapshot), "Sanity Check"); - // Use placement operator new to initialize static data area. - ::new ((void*)_snapshot) VirtualMemorySnapshot(); -} - void VirtualMemorySummary::snapshot(VirtualMemorySnapshot* s) { // Only if thread stack is backed by virtual memory if (ThreadStackTracker::track_as_vm()) { @@ -334,7 +328,6 @@ address ReservedMemoryRegion::thread_stack_uncommitted_bottom() const { bool VirtualMemoryTracker::initialize(NMT_TrackingLevel level) { assert(_reserved_regions == nullptr, "only call once"); if (level >= NMT_summary) { - VirtualMemorySummary::initialize(); _reserved_regions = new (std::nothrow, mtNMT) SortedLinkedList(); return (_reserved_regions != nullptr); diff --git a/src/hotspot/share/nmt/virtualMemoryTracker.hpp b/src/hotspot/share/nmt/virtualMemoryTracker.hpp index 06ca960febe1e..b4dd891f1c21f 100644 --- a/src/hotspot/share/nmt/virtualMemoryTracker.hpp +++ b/src/hotspot/share/nmt/virtualMemoryTracker.hpp @@ -132,7 +132,6 @@ class VirtualMemorySnapshot : public ResourceObj { class VirtualMemorySummary : AllStatic { public: - static void initialize(); static inline void record_reserved_memory(size_t size, MEMFLAGS flag) { as_snapshot()->by_type(flag)->reserve_memory(size); @@ -167,11 +166,11 @@ class VirtualMemorySummary : AllStatic { static void snapshot(VirtualMemorySnapshot* s); static VirtualMemorySnapshot* as_snapshot() { - return (VirtualMemorySnapshot*)_snapshot; + return &_snapshot; } private: - static size_t _snapshot[CALC_OBJ_SIZE_IN_TYPE(VirtualMemorySnapshot, size_t)]; + static VirtualMemorySnapshot _snapshot; };