8016556: G1: Use ArrayAllocator for BitMaps
Reviewed-by: tschatzl, dholmes, coleenp, johnc
This commit is contained in:
parent
5382e0759e
commit
3cc79df807
@ -713,13 +713,21 @@ public:
|
||||
// is set so that we always use malloc except for Solaris where we set the
|
||||
// limit to get mapped memory.
|
||||
template <class E, MEMFLAGS F>
|
||||
class ArrayAllocator : StackObj {
|
||||
class ArrayAllocator VALUE_OBJ_CLASS_SPEC {
|
||||
char* _addr;
|
||||
bool _use_malloc;
|
||||
size_t _size;
|
||||
bool _free_in_destructor;
|
||||
public:
|
||||
ArrayAllocator() : _addr(NULL), _use_malloc(false), _size(0) { }
|
||||
~ArrayAllocator() { free(); }
|
||||
ArrayAllocator(bool free_in_destructor = true) :
|
||||
_addr(NULL), _use_malloc(false), _size(0), _free_in_destructor(free_in_destructor) { }
|
||||
|
||||
~ArrayAllocator() {
|
||||
if (_free_in_destructor) {
|
||||
free();
|
||||
}
|
||||
}
|
||||
|
||||
E* allocate(size_t length);
|
||||
void free();
|
||||
};
|
||||
|
@ -41,7 +41,7 @@
|
||||
|
||||
|
||||
BitMap::BitMap(bm_word_t* map, idx_t size_in_bits) :
|
||||
_map(map), _size(size_in_bits)
|
||||
_map(map), _size(size_in_bits), _map_allocator(false)
|
||||
{
|
||||
assert(sizeof(bm_word_t) == BytesPerWord, "Implementation assumption.");
|
||||
assert(size_in_bits >= 0, "just checking");
|
||||
@ -49,7 +49,7 @@ BitMap::BitMap(bm_word_t* map, idx_t size_in_bits) :
|
||||
|
||||
|
||||
BitMap::BitMap(idx_t size_in_bits, bool in_resource_area) :
|
||||
_map(NULL), _size(0)
|
||||
_map(NULL), _size(0), _map_allocator(false)
|
||||
{
|
||||
assert(sizeof(bm_word_t) == BytesPerWord, "Implementation assumption.");
|
||||
resize(size_in_bits, in_resource_area);
|
||||
@ -65,8 +65,10 @@ void BitMap::resize(idx_t size_in_bits, bool in_resource_area) {
|
||||
if (in_resource_area) {
|
||||
_map = NEW_RESOURCE_ARRAY(bm_word_t, new_size_in_words);
|
||||
} else {
|
||||
if (old_map != NULL) FREE_C_HEAP_ARRAY(bm_word_t, _map, mtInternal);
|
||||
_map = NEW_C_HEAP_ARRAY(bm_word_t, new_size_in_words, mtInternal);
|
||||
if (old_map != NULL) {
|
||||
_map_allocator.free();
|
||||
}
|
||||
_map = _map_allocator.allocate(new_size_in_words);
|
||||
}
|
||||
Copy::disjoint_words((HeapWord*)old_map, (HeapWord*) _map,
|
||||
MIN2(old_size_in_words, new_size_in_words));
|
||||
|
@ -48,6 +48,7 @@ class BitMap VALUE_OBJ_CLASS_SPEC {
|
||||
} RangeSizeHint;
|
||||
|
||||
private:
|
||||
ArrayAllocator<bm_word_t, mtInternal> _map_allocator;
|
||||
bm_word_t* _map; // First word in bitmap
|
||||
idx_t _size; // Size of bitmap (in bits)
|
||||
|
||||
@ -113,7 +114,7 @@ class BitMap VALUE_OBJ_CLASS_SPEC {
|
||||
public:
|
||||
|
||||
// Constructs a bitmap with no map, and size 0.
|
||||
BitMap() : _map(NULL), _size(0) {}
|
||||
BitMap() : _map(NULL), _size(0), _map_allocator(false) {}
|
||||
|
||||
// Constructs a bitmap with the given map and size.
|
||||
BitMap(bm_word_t* map, idx_t size_in_bits);
|
||||
|
Loading…
Reference in New Issue
Block a user