Skip to content
Permalink
Browse files
8255232: G1: Make G1BiasedMappedArray freeable
Reviewed-by: ayang, kbarrett
  • Loading branch information
Thomas Schatzl committed Oct 29, 2020
1 parent 9e5bbff commit 5c520c3fdd62745deb4145061e75949e74450a3f
Showing 4 changed files with 33 additions and 8 deletions.
@@ -26,11 +26,23 @@
#include "gc/g1/g1BiasedArray.hpp"
#include "memory/padded.inline.hpp"

G1BiasedMappedArrayBase::G1BiasedMappedArrayBase() :
_alloc_base(NULL),
_base(NULL),
_length(0),
_biased_base(NULL),
_bias(0),
_shift_by(0) { }

G1BiasedMappedArrayBase::~G1BiasedMappedArrayBase() {
FreeHeap(_alloc_base);
}

// Allocate a new array, generic version.
address G1BiasedMappedArrayBase::create_new_base_array(size_t length, size_t elem_size) {
assert(length > 0, "just checking");
assert(elem_size > 0, "just checking");
return PaddedPrimitiveArray<u_char, mtGC>::create_unfreeable(length * elem_size);
return PaddedPrimitiveArray<u_char, mtGC>::create(length * elem_size, &_alloc_base);
}

#ifndef PRODUCT
@@ -25,17 +25,22 @@
#ifndef SHARE_GC_G1_G1BIASEDARRAY_HPP
#define SHARE_GC_G1_G1BIASEDARRAY_HPP

#include "memory/allocation.hpp"
#include "memory/memRegion.hpp"
#include "utilities/debug.hpp"
#include "utilities/powerOfTwo.hpp"

// Implements the common base functionality for arrays that contain provisions
// for accessing its elements using a biased index.
// The element type is defined by the instantiating the template.
class G1BiasedMappedArrayBase {
class G1BiasedMappedArrayBase : public CHeapObj<mtGC> {
friend class VMStructs;

void* _alloc_base; // the address the unpadded array has been allocated to

public:
typedef size_t idx_t;

protected:
address _base; // the real base address
size_t _length; // the length of the array
@@ -44,12 +49,10 @@ class G1BiasedMappedArrayBase {
uint _shift_by; // the amount of bits to shift right when mapping to an index of the array.

protected:

G1BiasedMappedArrayBase() : _base(NULL), _length(0), _biased_base(NULL),
_bias(0), _shift_by(0) { }
G1BiasedMappedArrayBase();

// Allocate a new array, generic version.
static address create_new_base_array(size_t length, size_t elem_size);
address create_new_base_array(size_t length, size_t elem_size);

// Initialize the members of this class. The biased start address of this array
// is the bias (in elements) multiplied by the element size.
@@ -90,8 +93,10 @@ class G1BiasedMappedArrayBase {
void verify_biased_index_inclusive_end(idx_t biased_index) const PRODUCT_RETURN;

public:
// Return the length of the array in elements.
size_t length() const { return _length; }
virtual ~G1BiasedMappedArrayBase();

// Return the length of the array in elements.
size_t length() const { return _length; }
};

// Array that provides biased access and mapping from (valid) addresses in the
@@ -116,6 +116,7 @@ template <class T, MEMFLAGS flags, size_t alignment = DEFAULT_CACHE_LINE_SIZE>
class PaddedPrimitiveArray {
public:
static T* create_unfreeable(size_t length);
static T* create(size_t length, void** alloc_base);
};

#endif // SHARE_MEMORY_PADDED_HPP
@@ -82,11 +82,18 @@ T** Padded2DArray<T, flags, alignment>::create_unfreeable(uint rows, uint column

template <class T, MEMFLAGS flags, size_t alignment>
T* PaddedPrimitiveArray<T, flags, alignment>::create_unfreeable(size_t length) {
void* temp;
return create(length, &temp);
}

template <class T, MEMFLAGS flags, size_t alignment>
T* PaddedPrimitiveArray<T, flags, alignment>::create(size_t length, void** alloc_base) {
// Allocate a chunk of memory large enough to allow for some alignment.
void* chunk = AllocateHeap(length * sizeof(T) + alignment, flags);

memset(chunk, 0, length * sizeof(T) + alignment);

*alloc_base = chunk;
return (T*)align_up(chunk, alignment);
}

1 comment on commit 5c520c3

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented on 5c520c3 Oct 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.