hotspot/src/share/vm/utilities/bitMap.hpp
author tschatzl
Wed, 06 Apr 2016 13:41:59 +0200
changeset 37414 2672ba9af0dc
parent 37413 2f71679d06dd
child 37466 287c4ebd11b0
permissions -rw-r--r--
8151386: Extract card live data out of G1ConcurrentMark Summary: Move card live data management out of G1ConcurrentMark into extra class G1CardLiveData managed by G1RemSet Reviewed-by: mgerdin, kbarrett
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
37414
2672ba9af0dc 8151386: Extract card live data out of G1ConcurrentMark
tschatzl
parents: 37413
diff changeset
     2
 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#ifndef SHARE_VM_UTILITIES_BITMAP_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#define SHARE_VM_UTILITIES_BITMAP_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "memory/allocation.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "utilities/top.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    31
// Forward decl;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    32
class BitMapClosure;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    34
// Operations for bitmaps represented as arrays of unsigned integers.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    35
// Bit offsets are numbered from 0 to size-1.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
class BitMap VALUE_OBJ_CLASS_SPEC {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  friend class BitMap2D;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  typedef size_t idx_t;         // Type used for bit and word indices.
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    42
  typedef uintptr_t bm_word_t;  // Element type of array that represents
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    43
                                // the bitmap.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  // Hints for range sizes.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  typedef enum {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
    unknown_range, small_range, large_range
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  } RangeSizeHint;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
 private:
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    51
  bm_word_t* _map;     // First word in bitmap
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    52
  idx_t      _size;    // Size of bitmap (in bits)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  // Puts the given value at the given offset, using resize() to size
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  // the bitmap appropriately if needed using factor-of-two expansion.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  void at_put_grow(idx_t index, bool value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  // Return the position of bit within the word that contains it (e.g., if
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  // bitmap words are 32 bits, return a number 0 <= n <= 31).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  static idx_t bit_in_word(idx_t bit) { return bit & (BitsPerWord - 1); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  // Return a mask that will select the specified bit, when applied to the word
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  // containing the bit.
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    65
  static bm_word_t bit_mask(idx_t bit) { return (bm_word_t)1 << bit_in_word(bit); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  // Return the index of the word containing the specified bit.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  static idx_t word_index(idx_t bit)  { return bit >> LogBitsPerWord; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  // Return the bit number of the first bit in the specified word.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  static idx_t bit_index(idx_t word)  { return word << LogBitsPerWord; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  // Return the array of bitmap words, or a specific word from it.
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    74
  bm_word_t* map() const           { return _map; }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    75
  bm_word_t  map(idx_t word) const { return _map[word]; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  // Return a pointer to the word containing the specified bit.
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    78
  bm_word_t* word_addr(idx_t bit) const { return map() + word_index(bit); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  // Set a word to a specified value or to all ones; clear a word.
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    81
  void set_word  (idx_t word, bm_word_t val) { _map[word] = val; }
26937
dd2b0f6de283 8059474: Clean up vm/utilities/Bitmap type uses
shade
parents: 22234
diff changeset
    82
  void set_word  (idx_t word)            { set_word(word, ~(bm_word_t)0); }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  void clear_word(idx_t word)            { _map[word] = 0; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  // Utilities for ranges of bits.  Ranges are half-open [beg, end).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  // Ranges within a single word.
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    88
  bm_word_t inverted_bit_mask_for_range(idx_t beg, idx_t end) const;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    89
  void  set_range_within_word      (idx_t beg, idx_t end);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    90
  void  clear_range_within_word    (idx_t beg, idx_t end);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    91
  void  par_put_range_within_word  (idx_t beg, idx_t end, bool value);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  // Ranges spanning entire words.
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    94
  void      set_range_of_words         (idx_t beg, idx_t end);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    95
  void      clear_range_of_words       (idx_t beg, idx_t end);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    96
  void      set_large_range_of_words   (idx_t beg, idx_t end);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    97
  void      clear_large_range_of_words (idx_t beg, idx_t end);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  // The index of the first full word in a range.
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   100
  idx_t word_index_round_up(idx_t bit) const;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
2998
b501bd305780 6849716: BitMap - performance regression introduced with G1
jcoomes
parents: 1374
diff changeset
   102
  // Verification.
37059
c482915a21aa 8151440: Move BitMap verfication inline functions out from bitMap.hpp
stefank
parents: 37058
diff changeset
   103
  void verify_index(idx_t index) const NOT_DEBUG_RETURN;
c482915a21aa 8151440: Move BitMap verfication inline functions out from bitMap.hpp
stefank
parents: 37058
diff changeset
   104
  void verify_range(idx_t beg_index, idx_t end_index) const NOT_DEBUG_RETURN;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
2998
b501bd305780 6849716: BitMap - performance regression introduced with G1
jcoomes
parents: 1374
diff changeset
   106
  // Statistics.
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   107
  static idx_t* _pop_count_table;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   108
  static void init_pop_count_table();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   109
  static idx_t num_set_bits(bm_word_t w);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   110
  static idx_t num_set_bits_from_table(unsigned char c);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  // Constructs a bitmap with no map, and size 0.
37057
03b3e1870228 8151436: Leaner ArrayAllocator and BitMaps
stefank
parents: 26937
diff changeset
   115
  BitMap() : _map(NULL), _size(0) {}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   117
  // Constructs a bitmap with the given map and size.
37058
47faedc8085b 8151439: Inline the BitMap constructor
stefank
parents: 37057
diff changeset
   118
  BitMap(bm_word_t* map, idx_t size_in_bits) :_map(map), _size(size_in_bits) {}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   120
  // Constructs an empty bitmap of the given size (that is, this clears the
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   121
  // new bitmap).  Allocates the map array in resource area if
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   122
  // "in_resource_area" is true, else in the C heap.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   123
  BitMap(idx_t size_in_bits, bool in_resource_area = true);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   125
  // Set the map and size.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   126
  void set_map(bm_word_t* map)      { _map = map; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  void set_size(idx_t size_in_bits) { _size = size_in_bits; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   129
  // Allocates necessary data structure, either in the resource area
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   130
  // or in the C heap, as indicated by "in_resource_area."
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  // Preserves state currently in bit map by copying data.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  // Zeros any newly-addressable bits.
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   133
  // If "in_resource_area" is false, frees the current map.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   134
  // (Note that this assumes that all calls to "resize" on the same BitMap
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   135
  // use the same value for "in_resource_area".)
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   136
  void resize(idx_t size_in_bits, bool in_resource_area = true);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
37413
2f71679d06dd 8077144: Concurrent mark initialization takes too long
tschatzl
parents: 37059
diff changeset
   138
  // Pretouch the entire range of memory this BitMap covers.
2f71679d06dd 8077144: Concurrent mark initialization takes too long
tschatzl
parents: 37059
diff changeset
   139
  void pretouch();
2f71679d06dd 8077144: Concurrent mark initialization takes too long
tschatzl
parents: 37059
diff changeset
   140
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  // Accessing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  idx_t size() const                    { return _size; }
37414
2672ba9af0dc 8151386: Extract card live data out of G1ConcurrentMark
tschatzl
parents: 37413
diff changeset
   143
  idx_t size_in_bytes() const           { return size_in_words() * BytesPerWord; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  idx_t size_in_words() const           {
37414
2672ba9af0dc 8151386: Extract card live data out of G1ConcurrentMark
tschatzl
parents: 37413
diff changeset
   145
    return calc_size_in_words(size());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
37414
2672ba9af0dc 8151386: Extract card live data out of G1ConcurrentMark
tschatzl
parents: 37413
diff changeset
   148
  static idx_t calc_size_in_words(size_t size_in_bits) {
37413
2f71679d06dd 8077144: Concurrent mark initialization takes too long
tschatzl
parents: 37059
diff changeset
   149
    return word_index(size_in_bits + BitsPerWord - 1);
2f71679d06dd 8077144: Concurrent mark initialization takes too long
tschatzl
parents: 37059
diff changeset
   150
  }
2f71679d06dd 8077144: Concurrent mark initialization takes too long
tschatzl
parents: 37059
diff changeset
   151
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  bool at(idx_t index) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
    verify_index(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
    return (*word_addr(index) & bit_mask(index)) != 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  // Align bit index up or down to the next bitmap word boundary, or check
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  // alignment.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  static idx_t word_align_up(idx_t bit) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
    return align_size_up(bit, BitsPerWord);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  static idx_t word_align_down(idx_t bit) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
    return align_size_down(bit, BitsPerWord);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  static bool is_word_aligned(idx_t bit) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
    return word_align_up(bit) == bit;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  // Set or clear the specified bit.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  inline void set_bit(idx_t bit);
9994
efb74fdbd46e 7046558: G1: concurrent marking optimizations
tonyp
parents: 7397
diff changeset
   171
  inline void clear_bit(idx_t bit);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  // Atomically set or clear the specified bit.
9994
efb74fdbd46e 7046558: G1: concurrent marking optimizations
tonyp
parents: 7397
diff changeset
   174
  inline bool par_set_bit(idx_t bit);
efb74fdbd46e 7046558: G1: concurrent marking optimizations
tonyp
parents: 7397
diff changeset
   175
  inline bool par_clear_bit(idx_t bit);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  // Put the given value at the given offset. The parallel version
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  // will CAS the value into the bitmap and is quite a bit slower.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  // The parallel version also returns a value indicating if the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  // calling thread was the one that changed the value of the bit.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  void at_put(idx_t index, bool value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  bool par_at_put(idx_t index, bool value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  // Update a range of bits.  Ranges are half-open [beg, end).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  void set_range   (idx_t beg, idx_t end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  void clear_range (idx_t beg, idx_t end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  void set_large_range   (idx_t beg, idx_t end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  void clear_large_range (idx_t beg, idx_t end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  void at_put_range(idx_t beg, idx_t end, bool value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  void par_at_put_range(idx_t beg, idx_t end, bool value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  void at_put_large_range(idx_t beg, idx_t end, bool value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  void par_at_put_large_range(idx_t beg, idx_t end, bool value);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  // Update a range of bits, using a hint about the size.  Currently only
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  // inlines the predominant case of a 1-bit range.  Works best when hint is a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  // compile-time constant.
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   197
  void set_range(idx_t beg, idx_t end, RangeSizeHint hint);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   198
  void clear_range(idx_t beg, idx_t end, RangeSizeHint hint);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   199
  void par_set_range(idx_t beg, idx_t end, RangeSizeHint hint);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   200
  void par_clear_range  (idx_t beg, idx_t end, RangeSizeHint hint);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   201
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  // Clearing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  void clear_large();
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   204
  inline void clear();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   206
  // Iteration support.  Returns "true" if the iteration completed, false
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   207
  // if the iteration terminated early (because the closure "blk" returned
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   208
  // false).
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   209
  bool iterate(BitMapClosure* blk, idx_t leftIndex, idx_t rightIndex);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   210
  bool iterate(BitMapClosure* blk) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
    // call the version that takes an interval
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   212
    return iterate(blk, 0, size());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   215
  // Looking for 1's and 0's at indices equal to or greater than "l_index",
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   216
  // stopping if none has been found before "r_index", and returning
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   217
  // "r_index" (which must be at most "size") in that case.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   218
  idx_t get_next_one_offset_inline (idx_t l_index, idx_t r_index) const;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   219
  idx_t get_next_zero_offset_inline(idx_t l_index, idx_t r_index) const;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   220
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   221
  // Like "get_next_one_offset_inline", except requires that "r_index" is
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   222
  // aligned to bitsizeof(bm_word_t).
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   223
  idx_t get_next_one_offset_inline_aligned_right(idx_t l_index,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   224
                                                        idx_t r_index) const;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   225
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   226
  // Non-inline versionsof the above.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  idx_t get_next_one_offset (idx_t l_index, idx_t r_index) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  idx_t get_next_zero_offset(idx_t l_index, idx_t r_index) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  idx_t get_next_one_offset(idx_t offset) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
    return get_next_one_offset(offset, size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  idx_t get_next_zero_offset(idx_t offset) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
    return get_next_zero_offset(offset, size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   237
  // Returns the number of bits set in the bitmap.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   238
  idx_t count_one_bits() const;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
  // Set operations.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
  void set_union(BitMap bits);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
  void set_difference(BitMap bits);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  void set_intersection(BitMap bits);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  // Returns true iff "this" is a superset of "bits".
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  bool contains(const BitMap bits) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
  // Returns true iff "this and "bits" have a non-empty intersection.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  bool intersects(const BitMap bits) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  // Returns result of whether this map changed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  // during the operation
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  bool set_union_with_result(BitMap bits);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  bool set_difference_with_result(BitMap bits);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  bool set_intersection_with_result(BitMap bits);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   255
  // Requires the submap of "bits" starting at offset to be at least as
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   256
  // large as "this".  Modifies "this" to be the intersection of its
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   257
  // current contents and the submap of "bits" starting at "offset" of the
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   258
  // same length as "this."
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   259
  // (For expedience, currently requires the offset to be aligned to the
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   260
  // bitsize of a uintptr_t.  This should go away in the future though it
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   261
  // will probably remain a good case to optimize.)
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   262
  void set_intersection_at_offset(BitMap bits, idx_t offset);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   263
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  void set_from(BitMap bits);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  bool is_same(BitMap bits);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  // Test if all bits are set or cleared
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  bool is_full() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  bool is_empty() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
16685
41c34debcde0 8011872: Include Bit Map addresses in the hs_err files
stefank
parents: 12272
diff changeset
   272
  void print_on_error(outputStream* st, const char* prefix) const;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
  // Printing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  void print_on(outputStream* st) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
// Convenience class wrapping BitMap which provides multiple bits per slot.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
class BitMap2D VALUE_OBJ_CLASS_SPEC {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
 public:
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   284
  typedef BitMap::idx_t idx_t;          // Type used for bit and word indices.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   285
  typedef BitMap::bm_word_t bm_word_t;  // Element type of array that
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   286
                                        // represents the bitmap.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  BitMap _map;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
  idx_t  _bits_per_slot;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
  idx_t bit_index(idx_t slot_index, idx_t bit_within_slot_index) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
    return slot_index * _bits_per_slot + bit_within_slot_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
  void verify_bit_within_slot_index(idx_t index) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
    assert(index < _bits_per_slot, "bit_within_slot index out of bounds");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  // Construction. bits_per_slot must be greater than 0.
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   301
  BitMap2D(bm_word_t* map, idx_t size_in_slots, idx_t bits_per_slot);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
  // Allocates necessary data structure in resource area. bits_per_slot must be greater than 0.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
  BitMap2D(idx_t size_in_slots, idx_t bits_per_slot);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
  idx_t size_in_bits() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
    return _map.size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
  // Returns number of full slots that have been allocated
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
  idx_t size_in_slots() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
    // Round down
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
    return _map.size() / _bits_per_slot;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
37059
c482915a21aa 8151440: Move BitMap verfication inline functions out from bitMap.hpp
stefank
parents: 37058
diff changeset
   316
  bool is_valid_index(idx_t slot_index, idx_t bit_within_slot_index);
c482915a21aa 8151440: Move BitMap verfication inline functions out from bitMap.hpp
stefank
parents: 37058
diff changeset
   317
  bool at(idx_t slot_index, idx_t bit_within_slot_index) const;
c482915a21aa 8151440: Move BitMap verfication inline functions out from bitMap.hpp
stefank
parents: 37058
diff changeset
   318
  void set_bit(idx_t slot_index, idx_t bit_within_slot_index);
c482915a21aa 8151440: Move BitMap verfication inline functions out from bitMap.hpp
stefank
parents: 37058
diff changeset
   319
  void clear_bit(idx_t slot_index, idx_t bit_within_slot_index);
c482915a21aa 8151440: Move BitMap verfication inline functions out from bitMap.hpp
stefank
parents: 37058
diff changeset
   320
  void at_put(idx_t slot_index, idx_t bit_within_slot_index, bool value);
c482915a21aa 8151440: Move BitMap verfication inline functions out from bitMap.hpp
stefank
parents: 37058
diff changeset
   321
  void at_put_grow(idx_t slot_index, idx_t bit_within_slot_index, bool value);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   322
  void clear();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   325
// Closure for iterating over BitMaps
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   327
class BitMapClosure VALUE_OBJ_CLASS_SPEC {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   328
 public:
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   329
  // Callback when bit in map is set.  Should normally return "true";
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   330
  // return of false indicates that the bitmap iteration should terminate.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   331
  virtual bool do_bit(BitMap::idx_t offset) = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   332
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   333
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   334
#endif // SHARE_VM_UTILITIES_BITMAP_HPP