Mercurial > hg > truffle
changeset 10992:b9d151496930
8016556: G1: Use ArrayAllocator for BitMaps
Reviewed-by: tschatzl, dholmes, coleenp, johnc
author | brutisso |
---|---|
date | Tue, 18 Jun 2013 22:45:32 +0200 |
parents | 01522ca68fc7 |
children | 493089fd29df |
files | src/share/vm/memory/allocation.hpp src/share/vm/utilities/bitMap.cpp src/share/vm/utilities/bitMap.hpp |
diffstat | 3 files changed, 19 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/src/share/vm/memory/allocation.hpp Tue Jun 18 12:31:07 2013 -0700 +++ b/src/share/vm/memory/allocation.hpp Tue Jun 18 22:45:32 2013 +0200 @@ -713,13 +713,21 @@ // 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(); };
--- a/src/share/vm/utilities/bitMap.cpp Tue Jun 18 12:31:07 2013 -0700 +++ b/src/share/vm/utilities/bitMap.cpp Tue Jun 18 22:45:32 2013 +0200 @@ -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(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 @@ 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));
--- a/src/share/vm/utilities/bitMap.hpp Tue Jun 18 12:31:07 2013 -0700 +++ b/src/share/vm/utilities/bitMap.hpp Tue Jun 18 22:45:32 2013 +0200 @@ -48,6 +48,7 @@ } 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 @@ 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);