11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_UTILITIES_BITMAP_HPP
26 #define SHARE_UTILITIES_BITMAP_HPP
27
28 #include "memory/allocation.hpp"
29 #include "runtime/atomic.hpp"
30 #include "utilities/align.hpp"
31
32 // Forward decl;
33 class BitMapClosure;
34
35 // Operations for bitmaps represented as arrays of unsigned integers.
36 // Bit offsets are numbered from 0 to size-1.
37
38 // The "abstract" base BitMap class.
39 //
40 // The constructor and destructor are protected to prevent
41 // creation of BitMap instances outside of the BitMap class.
42 //
43 // The BitMap class doesn't use virtual calls on purpose,
44 // this ensures that we don't get a vtable unnecessarily.
45 //
46 // The allocation of the backing storage for the BitMap are handled by
47 // the subclasses. BitMap doesn't allocate or delete backing storage.
48 class BitMap {
49 friend class BitMap2D;
50
351
352 // Set up and clear the bitmap memory.
353 //
354 // Precondition: The bitmap was default constructed and has
355 // not yet had memory allocated via resize or initialize.
356 void initialize(idx_t size_in_bits);
357
358 // Set up and clear the bitmap memory.
359 //
360 // Can be called on previously initialized bitmaps.
361 void reinitialize(idx_t size_in_bits);
362 };
363
364 // A BitMap with storage in a specific Arena.
365 class ArenaBitMap : public BitMap {
366 public:
367 // Clears the bitmap memory.
368 ArenaBitMap(Arena* arena, idx_t size_in_bits);
369
370 private:
371 // Don't allow copy or assignment.
372 ArenaBitMap(const ArenaBitMap&);
373 ArenaBitMap& operator=(const ArenaBitMap&);
374 };
375
376 // A BitMap with storage in the CHeap.
377 class CHeapBitMap : public BitMap {
378
379 private:
380 // Don't allow copy or assignment, to prevent the
381 // allocated memory from leaking out to other instances.
382 CHeapBitMap(const CHeapBitMap&);
383 CHeapBitMap& operator=(const CHeapBitMap&);
384
385 // NMT memory type
386 MEMFLAGS _flags;
387
388 public:
389 CHeapBitMap(MEMFLAGS flags = mtInternal) : BitMap(NULL, 0), _flags(flags) {}
390 // Clears the bitmap memory.
391 CHeapBitMap(idx_t size_in_bits, MEMFLAGS flags = mtInternal, bool clear = true);
392 ~CHeapBitMap();
393
394 // Resize the backing bitmap memory.
395 //
396 // Old bits are transfered to the new memory
397 // and the extended memory is (optionally) cleared.
398 void resize(idx_t new_size_in_bits, bool clear = true);
399
400 // Set up and (optionally) clear the bitmap memory.
401 //
402 // Precondition: The bitmap was default constructed and has
403 // not yet had memory allocated via resize or initialize.
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_UTILITIES_BITMAP_HPP
26 #define SHARE_UTILITIES_BITMAP_HPP
27
28 #include "memory/allocation.hpp"
29 #include "runtime/atomic.hpp"
30 #include "utilities/align.hpp"
31 #include "utilities/macros.hpp"
32
33 // Forward decl;
34 class BitMapClosure;
35
36 // Operations for bitmaps represented as arrays of unsigned integers.
37 // Bit offsets are numbered from 0 to size-1.
38
39 // The "abstract" base BitMap class.
40 //
41 // The constructor and destructor are protected to prevent
42 // creation of BitMap instances outside of the BitMap class.
43 //
44 // The BitMap class doesn't use virtual calls on purpose,
45 // this ensures that we don't get a vtable unnecessarily.
46 //
47 // The allocation of the backing storage for the BitMap are handled by
48 // the subclasses. BitMap doesn't allocate or delete backing storage.
49 class BitMap {
50 friend class BitMap2D;
51
352
353 // Set up and clear the bitmap memory.
354 //
355 // Precondition: The bitmap was default constructed and has
356 // not yet had memory allocated via resize or initialize.
357 void initialize(idx_t size_in_bits);
358
359 // Set up and clear the bitmap memory.
360 //
361 // Can be called on previously initialized bitmaps.
362 void reinitialize(idx_t size_in_bits);
363 };
364
365 // A BitMap with storage in a specific Arena.
366 class ArenaBitMap : public BitMap {
367 public:
368 // Clears the bitmap memory.
369 ArenaBitMap(Arena* arena, idx_t size_in_bits);
370
371 private:
372 NONCOPYABLE(ArenaBitMap);
373 };
374
375 // A BitMap with storage in the CHeap.
376 class CHeapBitMap : public BitMap {
377
378 private:
379 // Don't allow copy or assignment, to prevent the
380 // allocated memory from leaking out to other instances.
381 NONCOPYABLE(CHeapBitMap);
382
383 // NMT memory type
384 MEMFLAGS _flags;
385
386 public:
387 CHeapBitMap(MEMFLAGS flags = mtInternal) : BitMap(NULL, 0), _flags(flags) {}
388 // Clears the bitmap memory.
389 CHeapBitMap(idx_t size_in_bits, MEMFLAGS flags = mtInternal, bool clear = true);
390 ~CHeapBitMap();
391
392 // Resize the backing bitmap memory.
393 //
394 // Old bits are transfered to the new memory
395 // and the extended memory is (optionally) cleared.
396 void resize(idx_t new_size_in_bits, bool clear = true);
397
398 // Set up and (optionally) clear the bitmap memory.
399 //
400 // Precondition: The bitmap was default constructed and has
401 // not yet had memory allocated via resize or initialize.
|