Skip to content

Commit

Permalink
8320370: NMT: Change MallocMemorySnapshot to simplify code.
Browse files Browse the repository at this point in the history
Reviewed-by: stuefe, gziemski, stefank
  • Loading branch information
jdksjolen committed Dec 7, 2023
1 parent 58530f4 commit a7f6016
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 19 deletions.
4 changes: 1 addition & 3 deletions src/hotspot/share/nmt/mallocTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}

Expand Down
6 changes: 3 additions & 3 deletions src/hotspot/share/nmt/mallocTracker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/hotspot/share/nmt/nmtCommon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 1 addition & 8 deletions src/hotspot/share/nmt/virtualMemoryTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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()) {
Expand Down Expand Up @@ -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<ReservedMemoryRegion, compare_reserved_region_base>();
return (_reserved_regions != nullptr);
Expand Down
5 changes: 2 additions & 3 deletions src/hotspot/share/nmt/virtualMemoryTracker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
};


Expand Down

0 comments on commit a7f6016

Please sign in to comment.