src/share/vm/utilities/bitMap.cpp

Print this page
rev 6150 : 8037959: BitMap::resize frees old map before copying memory if !in_resource_area
Summary: Reorder BitMap::resize to copy the bitmap before freeing the old memory.
Reviewed-by:

*** 66,82 **** _size = size_in_bits; idx_t new_size_in_words = size_in_words(); if (in_resource_area) { _map = NEW_RESOURCE_ARRAY(bm_word_t, new_size_in_words); } else { - 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)); if (new_size_in_words > old_size_in_words) { clear_range_of_words(old_size_in_words, size_in_words()); } } --- 66,86 ---- _size = size_in_bits; idx_t new_size_in_words = size_in_words(); if (in_resource_area) { _map = NEW_RESOURCE_ARRAY(bm_word_t, new_size_in_words); } else { _map = _map_allocator.allocate(new_size_in_words); } + + if (old_map != NULL) { Copy::disjoint_words((HeapWord*)old_map, (HeapWord*) _map, MIN2(old_size_in_words, new_size_in_words)); + if (!in_resource_area) { + _map_allocator.free(); + } + } + if (new_size_in_words > old_size_in_words) { clear_range_of_words(old_size_in_words, size_in_words()); } }