提交 e8d900d1 编写于 作者: B brutisso

8016556: G1: Use ArrayAllocator for BitMaps

Reviewed-by: tschatzl, dholmes, coleenp, johnc
上级 7e320bca
...@@ -713,13 +713,21 @@ public: ...@@ -713,13 +713,21 @@ public:
// is set so that we always use malloc except for Solaris where we set the // is set so that we always use malloc except for Solaris where we set the
// limit to get mapped memory. // limit to get mapped memory.
template <class E, MEMFLAGS F> template <class E, MEMFLAGS F>
class ArrayAllocator : StackObj { class ArrayAllocator VALUE_OBJ_CLASS_SPEC {
char* _addr; char* _addr;
bool _use_malloc; bool _use_malloc;
size_t _size; size_t _size;
bool _free_in_destructor;
public: public:
ArrayAllocator() : _addr(NULL), _use_malloc(false), _size(0) { } ArrayAllocator(bool free_in_destructor = true) :
~ArrayAllocator() { free(); } _addr(NULL), _use_malloc(false), _size(0), _free_in_destructor(free_in_destructor) { }
~ArrayAllocator() {
if (_free_in_destructor) {
free();
}
}
E* allocate(size_t length); E* allocate(size_t length);
void free(); void free();
}; };
......
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
BitMap::BitMap(bm_word_t* map, idx_t size_in_bits) : 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(sizeof(bm_word_t) == BytesPerWord, "Implementation assumption.");
assert(size_in_bits >= 0, "just checking"); assert(size_in_bits >= 0, "just checking");
...@@ -49,7 +49,7 @@ BitMap::BitMap(bm_word_t* map, idx_t size_in_bits) : ...@@ -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) : 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."); assert(sizeof(bm_word_t) == BytesPerWord, "Implementation assumption.");
resize(size_in_bits, in_resource_area); resize(size_in_bits, in_resource_area);
...@@ -65,8 +65,10 @@ void BitMap::resize(idx_t size_in_bits, bool in_resource_area) { ...@@ -65,8 +65,10 @@ void BitMap::resize(idx_t size_in_bits, bool in_resource_area) {
if (in_resource_area) { if (in_resource_area) {
_map = NEW_RESOURCE_ARRAY(bm_word_t, new_size_in_words); _map = NEW_RESOURCE_ARRAY(bm_word_t, new_size_in_words);
} else { } else {
if (old_map != NULL) FREE_C_HEAP_ARRAY(bm_word_t, _map, mtInternal); if (old_map != NULL) {
_map = NEW_C_HEAP_ARRAY(bm_word_t, new_size_in_words, mtInternal); _map_allocator.free();
}
_map = _map_allocator.allocate(new_size_in_words);
} }
Copy::disjoint_words((HeapWord*)old_map, (HeapWord*) _map, Copy::disjoint_words((HeapWord*)old_map, (HeapWord*) _map,
MIN2(old_size_in_words, new_size_in_words)); MIN2(old_size_in_words, new_size_in_words));
......
...@@ -48,6 +48,7 @@ class BitMap VALUE_OBJ_CLASS_SPEC { ...@@ -48,6 +48,7 @@ class BitMap VALUE_OBJ_CLASS_SPEC {
} RangeSizeHint; } RangeSizeHint;
private: private:
ArrayAllocator<bm_word_t, mtInternal> _map_allocator;
bm_word_t* _map; // First word in bitmap bm_word_t* _map; // First word in bitmap
idx_t _size; // Size of bitmap (in bits) idx_t _size; // Size of bitmap (in bits)
...@@ -113,7 +114,7 @@ class BitMap VALUE_OBJ_CLASS_SPEC { ...@@ -113,7 +114,7 @@ class BitMap VALUE_OBJ_CLASS_SPEC {
public: public:
// Constructs a bitmap with no map, and size 0. // 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. // Constructs a bitmap with the given map and size.
BitMap(bm_word_t* map, idx_t size_in_bits); BitMap(bm_word_t* map, idx_t size_in_bits);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册