Skip to content

Commit 5c520c3

Browse files
author
Thomas Schatzl
committed
8255232: G1: Make G1BiasedMappedArray freeable
Reviewed-by: ayang, kbarrett
1 parent 9e5bbff commit 5c520c3

File tree

4 files changed

+33
-8
lines changed

4 files changed

+33
-8
lines changed

src/hotspot/share/gc/g1/g1BiasedArray.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,23 @@
2626
#include "gc/g1/g1BiasedArray.hpp"
2727
#include "memory/padded.inline.hpp"
2828

29+
G1BiasedMappedArrayBase::G1BiasedMappedArrayBase() :
30+
_alloc_base(NULL),
31+
_base(NULL),
32+
_length(0),
33+
_biased_base(NULL),
34+
_bias(0),
35+
_shift_by(0) { }
36+
37+
G1BiasedMappedArrayBase::~G1BiasedMappedArrayBase() {
38+
FreeHeap(_alloc_base);
39+
}
40+
2941
// Allocate a new array, generic version.
3042
address G1BiasedMappedArrayBase::create_new_base_array(size_t length, size_t elem_size) {
3143
assert(length > 0, "just checking");
3244
assert(elem_size > 0, "just checking");
33-
return PaddedPrimitiveArray<u_char, mtGC>::create_unfreeable(length * elem_size);
45+
return PaddedPrimitiveArray<u_char, mtGC>::create(length * elem_size, &_alloc_base);
3446
}
3547

3648
#ifndef PRODUCT

src/hotspot/share/gc/g1/g1BiasedArray.hpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,22 @@
2525
#ifndef SHARE_GC_G1_G1BIASEDARRAY_HPP
2626
#define SHARE_GC_G1_G1BIASEDARRAY_HPP
2727

28+
#include "memory/allocation.hpp"
2829
#include "memory/memRegion.hpp"
2930
#include "utilities/debug.hpp"
3031
#include "utilities/powerOfTwo.hpp"
3132

3233
// Implements the common base functionality for arrays that contain provisions
3334
// for accessing its elements using a biased index.
3435
// The element type is defined by the instantiating the template.
35-
class G1BiasedMappedArrayBase {
36+
class G1BiasedMappedArrayBase : public CHeapObj<mtGC> {
3637
friend class VMStructs;
38+
39+
void* _alloc_base; // the address the unpadded array has been allocated to
40+
3741
public:
3842
typedef size_t idx_t;
43+
3944
protected:
4045
address _base; // the real base address
4146
size_t _length; // the length of the array
@@ -44,12 +49,10 @@ class G1BiasedMappedArrayBase {
4449
uint _shift_by; // the amount of bits to shift right when mapping to an index of the array.
4550

4651
protected:
47-
48-
G1BiasedMappedArrayBase() : _base(NULL), _length(0), _biased_base(NULL),
49-
_bias(0), _shift_by(0) { }
52+
G1BiasedMappedArrayBase();
5053

5154
// Allocate a new array, generic version.
52-
static address create_new_base_array(size_t length, size_t elem_size);
55+
address create_new_base_array(size_t length, size_t elem_size);
5356

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

9295
public:
93-
// Return the length of the array in elements.
94-
size_t length() const { return _length; }
96+
virtual ~G1BiasedMappedArrayBase();
97+
98+
// Return the length of the array in elements.
99+
size_t length() const { return _length; }
95100
};
96101

97102
// Array that provides biased access and mapping from (valid) addresses in the

src/hotspot/share/memory/padded.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ template <class T, MEMFLAGS flags, size_t alignment = DEFAULT_CACHE_LINE_SIZE>
116116
class PaddedPrimitiveArray {
117117
public:
118118
static T* create_unfreeable(size_t length);
119+
static T* create(size_t length, void** alloc_base);
119120
};
120121

121122
#endif // SHARE_MEMORY_PADDED_HPP

src/hotspot/share/memory/padded.inline.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,18 @@ T** Padded2DArray<T, flags, alignment>::create_unfreeable(uint rows, uint column
8282

8383
template <class T, MEMFLAGS flags, size_t alignment>
8484
T* PaddedPrimitiveArray<T, flags, alignment>::create_unfreeable(size_t length) {
85+
void* temp;
86+
return create(length, &temp);
87+
}
88+
89+
template <class T, MEMFLAGS flags, size_t alignment>
90+
T* PaddedPrimitiveArray<T, flags, alignment>::create(size_t length, void** alloc_base) {
8591
// Allocate a chunk of memory large enough to allow for some alignment.
8692
void* chunk = AllocateHeap(length * sizeof(T) + alignment, flags);
8793

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

96+
*alloc_base = chunk;
9097
return (T*)align_up(chunk, alignment);
9198
}
9299

0 commit comments

Comments
 (0)