hotspot/src/share/vm/utilities/bitMap.inline.hpp
author ysr
Thu, 05 Jun 2008 15:57:56 -0700
changeset 1374 4c24294029a9
parent 1 489c9b5090e2
child 2998 b501bd305780
permissions -rw-r--r--
6711316: Open source the Garbage-First garbage collector Summary: First mercurial integration of the code for the Garbage-First garbage collector. Reviewed-by: apetrusenko, iveresov, jmasa, sgoldman, tonyp, ysr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2005-2006 Sun Microsystems, Inc.  All Rights Reserved.
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
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    25
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    26
inline void BitMap::set_bit(idx_t bit) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    27
  verify_index(bit);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    28
  *word_addr(bit) |= bit_mask(bit);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    29
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    30
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    31
inline void BitMap::clear_bit(idx_t bit) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    32
  verify_index(bit);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    33
  *word_addr(bit) &= ~bit_mask(bit);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    34
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    35
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
inline bool BitMap::par_set_bit(idx_t bit) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  verify_index(bit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  volatile idx_t* const addr = word_addr(bit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
  const idx_t mask = bit_mask(bit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  idx_t old_val = *addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  do {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
    const idx_t new_val = old_val | mask;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
    if (new_val == old_val) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
      return false;     // Someone else beat us to it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
    const idx_t cur_val = (idx_t) Atomic::cmpxchg_ptr((void*) new_val,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
                                                      (volatile void*) addr,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
                                                      (void*) old_val);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
    if (cur_val == old_val) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
      return true;      // Success.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    old_val = cur_val;  // The value changed, try again.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  } while (true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
inline bool BitMap::par_clear_bit(idx_t bit) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  verify_index(bit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  volatile idx_t* const addr = word_addr(bit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  const idx_t mask = ~bit_mask(bit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  idx_t old_val = *addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  do {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    const idx_t new_val = old_val & mask;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    if (new_val == old_val) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
      return false;     // Someone else beat us to it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
    const idx_t cur_val = (idx_t) Atomic::cmpxchg_ptr((void*) new_val,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
                                                      (volatile void*) addr,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
                                                      (void*) old_val);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    if (cur_val == old_val) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
      return true;      // Success.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    old_val = cur_val;  // The value changed, try again.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  } while (true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    78
inline void BitMap::set_range(idx_t beg, idx_t end, RangeSizeHint hint) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    79
  if (hint == small_range && end - beg == 1) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    80
    set_bit(beg);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    81
  } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    82
    if (hint == large_range) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    83
      set_large_range(beg, end);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    84
    } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    85
      set_range(beg, end);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    86
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    87
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    88
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    89
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    90
inline void BitMap::clear_range(idx_t beg, idx_t end, RangeSizeHint hint) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    91
  if (hint == small_range && end - beg == 1) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    92
    clear_bit(beg);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    93
  } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    94
    if (hint == large_range) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    95
      clear_large_range(beg, end);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    96
    } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    97
      clear_range(beg, end);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    98
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    99
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   100
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   101
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   102
inline void BitMap::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
   103
  if (hint == small_range && end - beg == 1) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   104
    par_at_put(beg, true);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   105
  } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   106
    if (hint == large_range) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   107
      par_at_put_large_range(beg, end, true);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   108
    } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   109
      par_at_put_range(beg, end, true);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   110
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   111
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   112
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   114
inline void BitMap::set_range_of_words(idx_t beg, idx_t end) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   115
  bm_word_t* map = _map;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   116
  for (idx_t i = beg; i < end; ++i) map[i] = ~(uintptr_t)0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   117
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   118
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   119
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   120
inline void BitMap::clear_range_of_words(idx_t beg, idx_t end) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   121
  bm_word_t* map = _map;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   122
  for (idx_t i = beg; i < end; ++i) map[i] = 0;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   123
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   124
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   125
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   126
inline void BitMap::clear() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   127
  clear_range_of_words(0, size_in_words());
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   128
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   129
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   131
inline void BitMap::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
   132
  if (hint == small_range && end - beg == 1) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   133
    par_at_put(beg, false);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   134
  } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   135
    if (hint == large_range) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   136
      par_at_put_large_range(beg, end, false);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   137
    } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   138
      par_at_put_range(beg, end, false);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   139
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   140
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   141
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   142
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   143
inline BitMap::idx_t
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   144
BitMap::get_next_one_offset_inline(idx_t l_offset, idx_t r_offset) const {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   145
  assert(l_offset <= size(), "BitMap index out of bounds");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   146
  assert(r_offset <= size(), "BitMap index out of bounds");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   147
  assert(l_offset <= r_offset, "l_offset > r_offset ?");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   148
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   149
  if (l_offset == r_offset) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   150
    return l_offset;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   151
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   152
  idx_t   index = word_index(l_offset);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   153
  idx_t r_index = word_index(r_offset-1) + 1;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   154
  idx_t res_offset = l_offset;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  // check bits including and to the _left_ of offset's position
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   157
  idx_t pos = bit_in_word(res_offset);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   158
  idx_t res = map(index) >> pos;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   159
  if (res != (uintptr_t)NoBits) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
    // find the position of the 1-bit
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   161
    for (; !(res & 1); res_offset++) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
      res = res >> 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
    }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   164
    assert(res_offset >= l_offset &&
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   165
           res_offset < r_offset, "just checking");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   166
    return MIN2(res_offset, r_offset);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  // skip over all word length 0-bit runs
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  for (index++; index < r_index; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
    res = map(index);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   171
    if (res != (uintptr_t)NoBits) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
      // found a 1, return the offset
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   173
      for (res_offset = bit_index(index); !(res & 1); res_offset++) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
        res = res >> 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
      assert(res & 1, "tautology; see loop condition");
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   177
      assert(res_offset >= l_offset, "just checking");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   178
      return MIN2(res_offset, r_offset);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   179
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   180
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   181
  return r_offset;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   182
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   183
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   184
inline BitMap::idx_t
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   185
BitMap::get_next_zero_offset_inline(idx_t l_offset, idx_t r_offset) const {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   186
  assert(l_offset <= size(), "BitMap index out of bounds");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   187
  assert(r_offset <= size(), "BitMap index out of bounds");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   188
  assert(l_offset <= r_offset, "l_offset > r_offset ?");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   189
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   190
  if (l_offset == r_offset) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   191
    return l_offset;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   192
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   193
  idx_t   index = word_index(l_offset);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   194
  idx_t r_index = word_index(r_offset-1) + 1;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   195
  idx_t res_offset = l_offset;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   196
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   197
  // check bits including and to the _left_ of offset's position
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   198
  idx_t pos = res_offset & (BitsPerWord - 1);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   199
  idx_t res = (map(index) >> pos) | left_n_bits((int)pos);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   200
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   201
  if (res != (uintptr_t)AllBits) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   202
    // find the position of the 0-bit
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   203
    for (; res & 1; res_offset++) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   204
      res = res >> 1;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   205
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   206
    assert(res_offset >= l_offset, "just checking");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   207
    return MIN2(res_offset, r_offset);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   208
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   209
  // skip over all word length 1-bit runs
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   210
  for (index++; index < r_index; index++) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   211
    res = map(index);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   212
    if (res != (uintptr_t)AllBits) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   213
      // found a 0, return the offset
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   214
      for (res_offset = index << LogBitsPerWord; res & 1;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   215
           res_offset++) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   216
        res = res >> 1;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   217
      }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   218
      assert(!(res & 1), "tautology; see loop condition");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   219
      assert(res_offset >= l_offset, "just checking");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   220
      return MIN2(res_offset, r_offset);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
  }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   223
  return r_offset;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   224
}
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
inline BitMap::idx_t
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   227
BitMap::get_next_one_offset_inline_aligned_right(idx_t l_offset,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   228
                                                 idx_t r_offset) const
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   229
{
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   230
  verify_range(l_offset, r_offset);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   231
  assert(bit_in_word(r_offset) == 0, "r_offset not word-aligned");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   232
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   233
  if (l_offset == r_offset) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   234
    return l_offset;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   235
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   236
  idx_t   index = word_index(l_offset);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   237
  idx_t r_index = word_index(r_offset);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   238
  idx_t res_offset = l_offset;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   239
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   240
  // check bits including and to the _left_ of offset's position
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   241
  idx_t res = map(index) >> bit_in_word(res_offset);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   242
  if (res != (uintptr_t)NoBits) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   243
    // find the position of the 1-bit
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   244
    for (; !(res & 1); res_offset++) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   245
      res = res >> 1;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   246
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   247
    assert(res_offset >= l_offset &&
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   248
           res_offset < r_offset, "just checking");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   249
    return res_offset;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   250
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   251
  // skip over all word length 0-bit runs
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   252
  for (index++; index < r_index; index++) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   253
    res = map(index);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   254
    if (res != (uintptr_t)NoBits) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   255
      // found a 1, return the offset
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   256
      for (res_offset = bit_index(index); !(res & 1); res_offset++) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   257
        res = res >> 1;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   258
      }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   259
      assert(res & 1, "tautology; see loop condition");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   260
      assert(res_offset >= l_offset && res_offset < r_offset, "just checking");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   261
      return res_offset;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   262
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   263
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   264
  return r_offset;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
}
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   266
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   267
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   268
// Returns a bit mask for a range of bits [beg, end) within a single word.  Each
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   269
// bit in the mask is 0 if the bit is in the range, 1 if not in the range.  The
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   270
// returned mask can be used directly to clear the range, or inverted to set the
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   271
// range.  Note:  end must not be 0.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   272
inline BitMap::bm_word_t
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   273
BitMap::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
   274
  assert(end != 0, "does not work when end == 0");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   275
  assert(beg == end || word_index(beg) == word_index(end - 1),
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   276
         "must be a single-word range");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   277
  bm_word_t mask = bit_mask(beg) - 1;   // low (right) bits
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   278
  if (bit_in_word(end) != 0) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   279
    mask |= ~(bit_mask(end) - 1);       // high (left) bits
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   280
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   281
  return mask;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   282
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   283
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   284
inline void BitMap::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
   285
  memset(_map + beg, ~(unsigned char)0, (end - beg) * sizeof(uintptr_t));
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   286
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   287
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   288
inline void BitMap::clear_large_range_of_words(idx_t beg, idx_t end) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   289
  memset(_map + beg, 0, (end - beg) * sizeof(uintptr_t));
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   290
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   291
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   292
inline BitMap::idx_t BitMap::word_index_round_up(idx_t bit) const {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   293
  idx_t bit_rounded_up = bit + (BitsPerWord - 1);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   294
  // Check for integer arithmetic overflow.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   295
  return bit_rounded_up > bit ? word_index(bit_rounded_up) : size_in_words();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   296
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   297
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   298
inline BitMap::idx_t BitMap::get_next_one_offset(idx_t l_offset,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   299
                                          idx_t r_offset) const {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   300
  return get_next_one_offset_inline(l_offset, r_offset);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   301
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   302
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   303
inline BitMap::idx_t BitMap::get_next_zero_offset(idx_t l_offset,
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   304
                                           idx_t r_offset) const {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   305
  return get_next_zero_offset_inline(l_offset, r_offset);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   306
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   307
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   308
inline void BitMap2D::clear() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   309
  _map.clear();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   310
}