equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
70 // ArenaBitMaps currently don't free memory. |
70 // ArenaBitMaps currently don't free memory. |
71 } |
71 } |
72 }; |
72 }; |
73 |
73 |
74 template <class Allocator> |
74 template <class Allocator> |
75 BitMap::bm_word_t* BitMap::reallocate(const Allocator& allocator, bm_word_t* old_map, idx_t old_size_in_bits, idx_t new_size_in_bits) { |
75 BitMap::bm_word_t* BitMap::reallocate(const Allocator& allocator, bm_word_t* old_map, idx_t old_size_in_bits, idx_t new_size_in_bits, bool clear) { |
76 size_t old_size_in_words = calc_size_in_words(old_size_in_bits); |
76 size_t old_size_in_words = calc_size_in_words(old_size_in_bits); |
77 size_t new_size_in_words = calc_size_in_words(new_size_in_bits); |
77 size_t new_size_in_words = calc_size_in_words(new_size_in_bits); |
78 |
78 |
79 bm_word_t* map = NULL; |
79 bm_word_t* map = NULL; |
80 |
80 |
84 if (old_map != NULL) { |
84 if (old_map != NULL) { |
85 Copy::disjoint_words((HeapWord*)old_map, (HeapWord*) map, |
85 Copy::disjoint_words((HeapWord*)old_map, (HeapWord*) map, |
86 MIN2(old_size_in_words, new_size_in_words)); |
86 MIN2(old_size_in_words, new_size_in_words)); |
87 } |
87 } |
88 |
88 |
89 if (new_size_in_words > old_size_in_words) { |
89 if (clear && new_size_in_words > old_size_in_words) { |
90 clear_range_of_words(map, old_size_in_words, new_size_in_words); |
90 clear_range_of_words(map, old_size_in_words, new_size_in_words); |
91 } |
91 } |
92 } |
92 } |
93 |
93 |
94 if (old_map != NULL) { |
94 if (old_map != NULL) { |
97 |
97 |
98 return map; |
98 return map; |
99 } |
99 } |
100 |
100 |
101 template <class Allocator> |
101 template <class Allocator> |
102 bm_word_t* BitMap::allocate(const Allocator& allocator, idx_t size_in_bits) { |
102 bm_word_t* BitMap::allocate(const Allocator& allocator, idx_t size_in_bits, bool clear) { |
103 // Reuse reallocate to ensure that the new memory is cleared. |
103 // Reuse reallocate to ensure that the new memory is cleared. |
104 return reallocate(allocator, NULL, 0, size_in_bits); |
104 return reallocate(allocator, NULL, 0, size_in_bits, clear); |
105 } |
105 } |
106 |
106 |
107 template <class Allocator> |
107 template <class Allocator> |
108 void BitMap::free(const Allocator& allocator, bm_word_t* map, idx_t size_in_bits) { |
108 void BitMap::free(const Allocator& allocator, bm_word_t* map, idx_t size_in_bits) { |
109 bm_word_t* ret = reallocate(allocator, map, size_in_bits, 0); |
109 bm_word_t* ret = reallocate(allocator, map, size_in_bits, 0); |
151 |
151 |
152 ArenaBitMap::ArenaBitMap(Arena* arena, idx_t size_in_bits) |
152 ArenaBitMap::ArenaBitMap(Arena* arena, idx_t size_in_bits) |
153 : BitMap(allocate(ArenaBitMapAllocator(arena), size_in_bits), size_in_bits) { |
153 : BitMap(allocate(ArenaBitMapAllocator(arena), size_in_bits), size_in_bits) { |
154 } |
154 } |
155 |
155 |
156 CHeapBitMap::CHeapBitMap(idx_t size_in_bits, MEMFLAGS flags) |
156 CHeapBitMap::CHeapBitMap(idx_t size_in_bits, MEMFLAGS flags, bool clear) |
157 : BitMap(allocate(CHeapBitMapAllocator(flags), size_in_bits), size_in_bits), _flags(flags) { |
157 : BitMap(allocate(CHeapBitMapAllocator(flags), size_in_bits, clear), size_in_bits), _flags(flags) { |
158 } |
158 } |
159 |
159 |
160 CHeapBitMap::~CHeapBitMap() { |
160 CHeapBitMap::~CHeapBitMap() { |
161 free(CHeapBitMapAllocator(_flags), map(), size()); |
161 free(CHeapBitMapAllocator(_flags), map(), size()); |
162 } |
162 } |