Skip to content

Commit

Permalink
8253640: Make MEMFLAGS an enum class
Browse files Browse the repository at this point in the history
Reviewed-by: stuefe, tschatzl
  • Loading branch information
stefank committed Sep 29, 2020
1 parent 86491a5 commit 3ed960e
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 34 deletions.
12 changes: 6 additions & 6 deletions src/hotspot/share/gc/g1/g1RegionToSpaceMapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ G1RegionToSpaceMapper::G1RegionToSpaceMapper(ReservedSpace rs,
size_t page_size,
size_t region_granularity,
size_t commit_factor,
MemoryType type) :
MEMFLAGS type) :
_listener(NULL),
_storage(rs, used_size, page_size),
_region_granularity(region_granularity),
Expand All @@ -67,7 +67,7 @@ class G1RegionsLargerThanCommitSizeMapper : public G1RegionToSpaceMapper {
size_t page_size,
size_t alloc_granularity,
size_t commit_factor,
MemoryType type) :
MEMFLAGS type) :
G1RegionToSpaceMapper(rs, actual_size, page_size, alloc_granularity, commit_factor, type),
_pages_per_region(alloc_granularity / (page_size * commit_factor)) {

Expand Down Expand Up @@ -130,7 +130,7 @@ class G1RegionsSmallerThanCommitSizeMapper : public G1RegionToSpaceMapper {
size_t page_size,
size_t alloc_granularity,
size_t commit_factor,
MemoryType type) :
MEMFLAGS type) :
G1RegionToSpaceMapper(rs, actual_size, page_size, alloc_granularity, commit_factor, type),
_regions_per_page((page_size * commit_factor) / alloc_granularity) {

Expand Down Expand Up @@ -240,7 +240,7 @@ G1RegionToHeteroSpaceMapper::G1RegionToHeteroSpaceMapper(ReservedSpace rs,
size_t page_size,
size_t alloc_granularity,
size_t commit_factor,
MemoryType type) :
MEMFLAGS type) :
G1RegionToSpaceMapper(rs, actual_size, page_size, alloc_granularity, commit_factor, type),
_rs(rs),
_dram_mapper(NULL),
Expand Down Expand Up @@ -337,7 +337,7 @@ G1RegionToSpaceMapper* G1RegionToSpaceMapper::create_heap_mapper(ReservedSpace r
size_t page_size,
size_t region_granularity,
size_t commit_factor,
MemoryType type) {
MEMFLAGS type) {
if (AllocateOldGenAt != NULL) {
G1RegionToHeteroSpaceMapper* mapper = new G1RegionToHeteroSpaceMapper(rs, actual_size, page_size, region_granularity, commit_factor, type);
if (!mapper->initialize()) {
Expand All @@ -355,7 +355,7 @@ G1RegionToSpaceMapper* G1RegionToSpaceMapper::create_mapper(ReservedSpace rs,
size_t page_size,
size_t region_granularity,
size_t commit_factor,
MemoryType type) {
MEMFLAGS type) {
if (region_granularity >= (page_size * commit_factor)) {
return new G1RegionsLargerThanCommitSizeMapper(rs, actual_size, page_size, region_granularity, commit_factor, type);
} else {
Expand Down
12 changes: 6 additions & 6 deletions src/hotspot/share/gc/g1/g1RegionToSpaceMapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ class G1RegionToSpaceMapper : public CHeapObj<mtGC> {
// Mapping management
CHeapBitMap _region_commit_map;

MemoryType _memory_type;
MEMFLAGS _memory_type;

G1RegionToSpaceMapper(ReservedSpace rs, size_t used_size, size_t page_size, size_t region_granularity, size_t commit_factor, MemoryType type);
G1RegionToSpaceMapper(ReservedSpace rs, size_t used_size, size_t page_size, size_t region_granularity, size_t commit_factor, MEMFLAGS type);

void fire_on_commit(uint start_idx, size_t num_regions, bool zero_filled);
public:
Expand Down Expand Up @@ -85,14 +85,14 @@ class G1RegionToSpaceMapper : public CHeapObj<mtGC> {
size_t page_size,
size_t region_granularity,
size_t byte_translation_factor,
MemoryType type);
MEMFLAGS type);

static G1RegionToSpaceMapper* create_heap_mapper(ReservedSpace rs,
size_t actual_size,
size_t page_size,
size_t region_granularity,
size_t byte_translation_factor,
MemoryType type);
MEMFLAGS type);
};

// G1RegionToSpaceMapper implementation where
Expand All @@ -106,10 +106,10 @@ class G1RegionToHeteroSpaceMapper : public G1RegionToSpaceMapper {
uint _start_index_of_dram;
size_t _page_size;
size_t _commit_factor;
MemoryType _type;
MEMFLAGS _type;

public:
G1RegionToHeteroSpaceMapper(ReservedSpace rs, size_t used_size, size_t page_size, size_t region_granularity, size_t commit_factor, MemoryType type);
G1RegionToHeteroSpaceMapper(ReservedSpace rs, size_t used_size, size_t page_size, size_t region_granularity, size_t commit_factor, MEMFLAGS type);
bool initialize();
uint num_committed_dram() const;
uint num_committed_nvdimm() const;
Expand Down
10 changes: 8 additions & 2 deletions src/hotspot/share/memory/allocation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,20 @@ class AllocatedObj {
/*
* Memory types
*/
enum MemoryType {
enum class MEMFLAGS {
MEMORY_TYPES_DO(MEMORY_TYPE_DECLARE_ENUM)
mt_number_of_types // number of memory types (mtDontTrack
// is not included as validate type)
};

typedef MemoryType MEMFLAGS;
#define MEMORY_TYPE_SHORTNAME(type, human_readable) \
constexpr MEMFLAGS type = MEMFLAGS::type;

// Generate short aliases for the enum values. E.g. mtGC instead of MEMFLAGS::mtGC.
MEMORY_TYPES_DO(MEMORY_TYPE_SHORTNAME)

// Make an int version of the sentinel end value.
constexpr int mt_number_of_types = static_cast<int>(MEMFLAGS::mt_number_of_types);

#if INCLUDE_NMT

Expand Down
8 changes: 1 addition & 7 deletions src/hotspot/share/services/mallocTracker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,6 @@ class MallocMemorySnapshot : public ResourceObj {
return &_malloc[index];
}

inline MallocMemory* by_index(int index) {
assert(index >= 0, "Index out of bound");
assert(index < mt_number_of_types, "Index out of bound");
return &_malloc[index];
}

inline MemoryCounter* malloc_overhead() {
return &_tracking_header;
}
Expand Down Expand Up @@ -269,7 +263,7 @@ class MallocHeader {
return;
}

_flags = flags;
_flags = NMTUtil::flag_to_index(flags);
set_size(size);
if (level == NMT_detail) {
size_t bucket_idx;
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/services/memBaseline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ int compare_malloc_site(const MallocSite& s1, const MallocSite& s2) {
int compare_malloc_site_and_type(const MallocSite& s1, const MallocSite& s2) {
int res = compare_malloc_site(s1, s2);
if (res == 0) {
res = (int)(s1.flag() - s2.flag());
res = (int)(NMTUtil::flag_to_index(s1.flag()) - NMTUtil::flag_to_index(s2.flag()));
}

return res;
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/services/memReporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ void MemDetailReporter::report_malloc_sites() {
stack->print_on(out);
out->print("%29s", " ");
MEMFLAGS flag = malloc_site->flag();
assert((flag >= 0 && flag < (int)mt_number_of_types) && flag != mtNone,
assert(NMTUtil::flag_is_valid(flag) && flag != mtNone,
"Must have a valid memory type");
print_malloc(malloc_site->size(), malloc_site->count(),flag);
out->print_cr("\n");
Expand Down
20 changes: 15 additions & 5 deletions src/hotspot/share/services/nmtCommon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,21 @@ const int NMT_TrackingStackDepth = 4;
// A few common utilities for native memory tracking
class NMTUtil : AllStatic {
public:
// Check if index is a valid MEMFLAGS enum value (including mtNone)
static inline bool flag_index_is_valid(int index) {
return index >= 0 && index < mt_number_of_types;
}

// Check if flag value is a valid MEMFLAGS enum value (including mtNone)
static inline bool flag_is_valid(MEMFLAGS flag) {
const int index = static_cast<int>(flag);
return flag_index_is_valid(index);
}

// Map memory type to index
static inline int flag_to_index(MEMFLAGS flag) {
const int index = flag & 0xff;
assert(index >= 0 && index < (int)mt_number_of_types, "Index out of bounds");
return index;
assert(flag_is_valid(flag), "Invalid flag");
return static_cast<int>(flag);
}

// Map memory type to human readable name
Expand All @@ -61,8 +71,8 @@ class NMTUtil : AllStatic {

// Map an index to memory type
static MEMFLAGS index_to_flag(int index) {
assert(index >= 0 && index < (int) mt_number_of_types, "Index out of bounds");
return (MEMFLAGS)index;
assert(flag_index_is_valid(index), "Invalid flag");
return static_cast<MEMFLAGS>(index);
}

// Memory size scale
Expand Down
6 changes: 0 additions & 6 deletions src/hotspot/share/services/virtualMemoryTracker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,6 @@ class VirtualMemorySnapshot : public ResourceObj {
return &_virtual_memory[index];
}

inline VirtualMemory* by_index(int index) {
assert(index >= 0, "Index out of bound");
assert(index < mt_number_of_types, "Index out of bound");
return &_virtual_memory[index];
}

inline size_t total_reserved() const {
size_t amount = 0;
for (int index = 0; index < mt_number_of_types; index ++) {
Expand Down

1 comment on commit 3ed960e

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented on 3ed960e Sep 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.