Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8240590: Add MemRegion::destroy_array to complement introduced create…
…_array

Reviewed-by: lkorinth, sjohanss
  • Loading branch information
Thomas Schatzl committed Mar 20, 2020
1 parent e7204cb commit cc83c45595fe4a0a3930014cce62e5c9dc6d8f40
@@ -269,7 +269,7 @@ G1CMRootMemRegions::G1CMRootMemRegions(uint const max_regions) :
_should_abort(false) { }

G1CMRootMemRegions::~G1CMRootMemRegions() {
FREE_C_HEAP_ARRAY(MemRegion, _root_regions);
MemRegion::destroy_array(_root_regions, _max_regions);
}

void G1CMRootMemRegions::reset() {
@@ -62,8 +62,8 @@ CardTable::CardTable(MemRegion whole_heap, bool conc_scan) :
}

CardTable::~CardTable() {
FREE_C_HEAP_ARRAY(MemRegion, _covered);
FREE_C_HEAP_ARRAY(MemRegion, _committed);
MemRegion::destroy_array(_covered, _max_covered_regions);
MemRegion::destroy_array(_committed, _max_covered_regions);
}

void CardTable::initialize() {
@@ -1782,10 +1782,11 @@ bool FileMapInfo::map_heap_data(MemRegion **heap_mem, int first,

struct Cleanup {
MemRegion* _regions;
uint _length;
bool _aborted;
Cleanup(MemRegion* regions) : _regions(regions), _aborted(true) { }
~Cleanup() { if (_aborted) { FREE_C_HEAP_ARRAY(MemRegion, _regions); } }
} cleanup(regions);
Cleanup(MemRegion* regions, uint length) : _regions(regions), _length(length), _aborted(true) { }
~Cleanup() { if (_aborted) { MemRegion::destroy_array(_regions, _length); } }
} cleanup(regions, max);

FileMapRegion* si;
int region_num = 0;
@@ -102,10 +102,20 @@ MemRegion MemRegion::minus(const MemRegion mr2) const {
return MemRegion();
}

MemRegion* MemRegion::create_array(uint length, MEMFLAGS flags) {
MemRegion* MemRegion::create_array(size_t length, MEMFLAGS flags) {
MemRegion* result = NEW_C_HEAP_ARRAY(MemRegion, length, flags);
for (uint i = 0; i < length; i++) {
for (size_t i = 0; i < length; i++) {
::new (&result[i]) MemRegion();
}
return result;
}

void MemRegion::destroy_array(MemRegion* array, size_t length) {
if (array == NULL) {
return;
}
for (size_t i = 0; i < length; i++) {
array[i].~MemRegion();
}
FREE_C_HEAP_ARRAY(MemRegion, array);
}
@@ -94,7 +94,8 @@ class MemRegion {
bool is_empty() const { return word_size() == 0; }

// Creates and initializes an array of MemRegions of the given length.
static MemRegion* create_array(uint length, MEMFLAGS flags);
static MemRegion* create_array(size_t length, MEMFLAGS flags);
static void destroy_array(MemRegion* array, size_t length);
};

// For iteration over MemRegion's.

0 comments on commit cc83c45

Please sign in to comment.