Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8253640: Make MEMFLAGS an enum class
Reviewed-by: stuefe, tschatzl
  • Loading branch information
stefank committed Sep 29, 2020
1 parent 86491a5 commit 3ed960ec77f3f2d9df3244806ae0fe635052dbd6
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 34 deletions.
@@ -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),
@@ -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)) {

@@ -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) {

@@ -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),
@@ -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()) {
@@ -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 {
@@ -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:
@@ -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
@@ -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;
@@ -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

@@ -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;
}
@@ -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;
@@ -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;
@@ -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");
@@ -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
@@ -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
@@ -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 ++) {

0 comments on commit 3ed960e

Please sign in to comment.