Tue, 18 Jun 2013 22:45:32 +0200
8016556: G1: Use ArrayAllocator for BitMaps
Reviewed-by: tschatzl, dholmes, coleenp, johnc
1.1 --- a/src/share/vm/memory/allocation.hpp Tue Jun 18 12:31:07 2013 -0700 1.2 +++ b/src/share/vm/memory/allocation.hpp Tue Jun 18 22:45:32 2013 +0200 1.3 @@ -713,13 +713,21 @@ 1.4 // is set so that we always use malloc except for Solaris where we set the 1.5 // limit to get mapped memory. 1.6 template <class E, MEMFLAGS F> 1.7 -class ArrayAllocator : StackObj { 1.8 +class ArrayAllocator VALUE_OBJ_CLASS_SPEC { 1.9 char* _addr; 1.10 bool _use_malloc; 1.11 size_t _size; 1.12 + bool _free_in_destructor; 1.13 public: 1.14 - ArrayAllocator() : _addr(NULL), _use_malloc(false), _size(0) { } 1.15 - ~ArrayAllocator() { free(); } 1.16 + ArrayAllocator(bool free_in_destructor = true) : 1.17 + _addr(NULL), _use_malloc(false), _size(0), _free_in_destructor(free_in_destructor) { } 1.18 + 1.19 + ~ArrayAllocator() { 1.20 + if (_free_in_destructor) { 1.21 + free(); 1.22 + } 1.23 + } 1.24 + 1.25 E* allocate(size_t length); 1.26 void free(); 1.27 };
2.1 --- a/src/share/vm/utilities/bitMap.cpp Tue Jun 18 12:31:07 2013 -0700 2.2 +++ b/src/share/vm/utilities/bitMap.cpp Tue Jun 18 22:45:32 2013 +0200 2.3 @@ -41,7 +41,7 @@ 2.4 2.5 2.6 BitMap::BitMap(bm_word_t* map, idx_t size_in_bits) : 2.7 - _map(map), _size(size_in_bits) 2.8 + _map(map), _size(size_in_bits), _map_allocator(false) 2.9 { 2.10 assert(sizeof(bm_word_t) == BytesPerWord, "Implementation assumption."); 2.11 assert(size_in_bits >= 0, "just checking"); 2.12 @@ -49,7 +49,7 @@ 2.13 2.14 2.15 BitMap::BitMap(idx_t size_in_bits, bool in_resource_area) : 2.16 - _map(NULL), _size(0) 2.17 + _map(NULL), _size(0), _map_allocator(false) 2.18 { 2.19 assert(sizeof(bm_word_t) == BytesPerWord, "Implementation assumption."); 2.20 resize(size_in_bits, in_resource_area); 2.21 @@ -65,8 +65,10 @@ 2.22 if (in_resource_area) { 2.23 _map = NEW_RESOURCE_ARRAY(bm_word_t, new_size_in_words); 2.24 } else { 2.25 - if (old_map != NULL) FREE_C_HEAP_ARRAY(bm_word_t, _map, mtInternal); 2.26 - _map = NEW_C_HEAP_ARRAY(bm_word_t, new_size_in_words, mtInternal); 2.27 + if (old_map != NULL) { 2.28 + _map_allocator.free(); 2.29 + } 2.30 + _map = _map_allocator.allocate(new_size_in_words); 2.31 } 2.32 Copy::disjoint_words((HeapWord*)old_map, (HeapWord*) _map, 2.33 MIN2(old_size_in_words, new_size_in_words));
3.1 --- a/src/share/vm/utilities/bitMap.hpp Tue Jun 18 12:31:07 2013 -0700 3.2 +++ b/src/share/vm/utilities/bitMap.hpp Tue Jun 18 22:45:32 2013 +0200 3.3 @@ -48,6 +48,7 @@ 3.4 } RangeSizeHint; 3.5 3.6 private: 3.7 + ArrayAllocator<bm_word_t, mtInternal> _map_allocator; 3.8 bm_word_t* _map; // First word in bitmap 3.9 idx_t _size; // Size of bitmap (in bits) 3.10 3.11 @@ -113,7 +114,7 @@ 3.12 public: 3.13 3.14 // Constructs a bitmap with no map, and size 0. 3.15 - BitMap() : _map(NULL), _size(0) {} 3.16 + BitMap() : _map(NULL), _size(0), _map_allocator(false) {} 3.17 3.18 // Constructs a bitmap with the given map and size. 3.19 BitMap(bm_word_t* map, idx_t size_in_bits);