hotspot/src/share/vm/utilities/bitMap.inline.hpp
author stefank
Tue, 23 Nov 2010 13:22:55 -0800
changeset 7397 5b173b4ca846
parent 5547 f4b087cbb361
child 11574 8a7fe61966c0
permissions -rw-r--r--
6989984: Use standard include model for Hospot Summary: Replaced MakeDeps and the includeDB files with more standardized solutions. Reviewed-by: coleenp, kvn, kamg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
     2
 * Copyright (c) 2005, 2010, 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_INLINE_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#define SHARE_VM_UTILITIES_BITMAP_INLINE_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 "runtime/atomic.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    29
#include "utilities/bitMap.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    30
2998
b501bd305780 6849716: BitMap - performance regression introduced with G1
jcoomes
parents: 1374
diff changeset
    31
#ifdef ASSERT
b501bd305780 6849716: BitMap - performance regression introduced with G1
jcoomes
parents: 1374
diff changeset
    32
inline void BitMap::verify_index(idx_t index) const {
b501bd305780 6849716: BitMap - performance regression introduced with G1
jcoomes
parents: 1374
diff changeset
    33
  assert(index < _size, "BitMap index out of bounds");
b501bd305780 6849716: BitMap - performance regression introduced with G1
jcoomes
parents: 1374
diff changeset
    34
}
b501bd305780 6849716: BitMap - performance regression introduced with G1
jcoomes
parents: 1374
diff changeset
    35
b501bd305780 6849716: BitMap - performance regression introduced with G1
jcoomes
parents: 1374
diff changeset
    36
inline void BitMap::verify_range(idx_t beg_index, idx_t end_index) const {
b501bd305780 6849716: BitMap - performance regression introduced with G1
jcoomes
parents: 1374
diff changeset
    37
  assert(beg_index <= end_index, "BitMap range error");
b501bd305780 6849716: BitMap - performance regression introduced with G1
jcoomes
parents: 1374
diff changeset
    38
  // Note that [0,0) and [size,size) are both valid ranges.
b501bd305780 6849716: BitMap - performance regression introduced with G1
jcoomes
parents: 1374
diff changeset
    39
  if (end_index != _size) verify_index(end_index);
b501bd305780 6849716: BitMap - performance regression introduced with G1
jcoomes
parents: 1374
diff changeset
    40
}
b501bd305780 6849716: BitMap - performance regression introduced with G1
jcoomes
parents: 1374
diff changeset
    41
#endif // #ifdef ASSERT
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    42
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    43
inline void BitMap::set_bit(idx_t bit) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    44
  verify_index(bit);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    45
  *word_addr(bit) |= bit_mask(bit);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    46
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    47
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    48
inline void BitMap::clear_bit(idx_t bit) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    49
  verify_index(bit);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    50
  *word_addr(bit) &= ~bit_mask(bit);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    51
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    52
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
inline bool BitMap::par_set_bit(idx_t bit) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  verify_index(bit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  volatile idx_t* const addr = word_addr(bit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  const idx_t mask = bit_mask(bit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  idx_t old_val = *addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  do {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
    const idx_t new_val = old_val | mask;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    if (new_val == old_val) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
      return false;     // Someone else beat us to it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    const idx_t cur_val = (idx_t) Atomic::cmpxchg_ptr((void*) new_val,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
                                                      (volatile void*) addr,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
                                                      (void*) old_val);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    if (cur_val == old_val) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
      return true;      // Success.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
    old_val = cur_val;  // The value changed, try again.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  } while (true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
inline bool BitMap::par_clear_bit(idx_t bit) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  verify_index(bit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  volatile idx_t* const addr = word_addr(bit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  const idx_t mask = ~bit_mask(bit);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  idx_t old_val = *addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  do {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    const idx_t new_val = old_val & mask;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    if (new_val == old_val) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
      return false;     // Someone else beat us to it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    const idx_t cur_val = (idx_t) Atomic::cmpxchg_ptr((void*) new_val,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
                                                      (volatile void*) addr,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
                                                      (void*) old_val);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
    if (cur_val == old_val) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
      return true;      // Success.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    old_val = cur_val;  // The value changed, try again.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  } while (true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    95
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
    96
  if (hint == small_range && end - beg == 1) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    97
    set_bit(beg);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    98
  } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
    99
    if (hint == large_range) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   100
      set_large_range(beg, end);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   101
    } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   102
      set_range(beg, end);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   103
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   104
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   105
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   106
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   107
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
   108
  if (hint == small_range && end - beg == 1) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   109
    clear_bit(beg);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   110
  } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   111
    if (hint == large_range) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   112
      clear_large_range(beg, end);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   113
    } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   114
      clear_range(beg, end);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   115
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   116
  }
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
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
   120
  if (hint == small_range && end - beg == 1) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   121
    par_at_put(beg, true);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   122
  } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   123
    if (hint == large_range) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   124
      par_at_put_large_range(beg, end, true);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   125
    } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   126
      par_at_put_range(beg, end, true);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   127
    }
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::set_range_of_words(idx_t beg, idx_t end) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   132
  bm_word_t* map = _map;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   133
  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
   134
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   135
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   136
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   137
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
   138
  bm_word_t* map = _map;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   139
  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
   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 void BitMap::clear() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   144
  clear_range_of_words(0, size_in_words());
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   145
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   146
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   148
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
   149
  if (hint == small_range && end - beg == 1) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   150
    par_at_put(beg, false);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   151
  } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   152
    if (hint == large_range) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   153
      par_at_put_large_range(beg, end, false);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   154
    } else {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   155
      par_at_put_range(beg, end, false);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   156
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   157
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   158
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   159
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   160
inline BitMap::idx_t
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   161
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
   162
  assert(l_offset <= size(), "BitMap index out of bounds");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   163
  assert(r_offset <= size(), "BitMap index out of bounds");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   164
  assert(l_offset <= r_offset, "l_offset > r_offset ?");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   165
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   166
  if (l_offset == r_offset) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   167
    return l_offset;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   168
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   169
  idx_t   index = word_index(l_offset);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   170
  idx_t r_index = word_index(r_offset-1) + 1;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   171
  idx_t res_offset = l_offset;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  // 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
   174
  idx_t pos = bit_in_word(res_offset);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   175
  idx_t res = map(index) >> pos;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   176
  if (res != (uintptr_t)NoBits) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
    // find the position of the 1-bit
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   178
    for (; !(res & 1); res_offset++) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
      res = res >> 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   181
    assert(res_offset >= l_offset &&
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   182
           res_offset < r_offset, "just checking");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   183
    return MIN2(res_offset, r_offset);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  // skip over all word length 0-bit runs
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  for (index++; index < r_index; index++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
    res = map(index);
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   188
    if (res != (uintptr_t)NoBits) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
      // found a 1, return the offset
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   190
      for (res_offset = bit_index(index); !(res & 1); res_offset++) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
        res = res >> 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
      assert(res & 1, "tautology; see loop condition");
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   194
      assert(res_offset >= l_offset, "just checking");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   195
      return MIN2(res_offset, r_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
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   198
  return r_offset;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   199
}
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
inline BitMap::idx_t
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   202
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
   203
  assert(l_offset <= size(), "BitMap index out of bounds");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   204
  assert(r_offset <= size(), "BitMap index out of bounds");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   205
  assert(l_offset <= r_offset, "l_offset > r_offset ?");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   206
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   207
  if (l_offset == r_offset) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   208
    return l_offset;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   209
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   210
  idx_t   index = word_index(l_offset);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   211
  idx_t r_index = word_index(r_offset-1) + 1;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   212
  idx_t res_offset = l_offset;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   213
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   214
  // 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
   215
  idx_t pos = res_offset & (BitsPerWord - 1);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   216
  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
   217
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   218
  if (res != (uintptr_t)AllBits) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   219
    // find the position of the 0-bit
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   220
    for (; res & 1; res_offset++) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   221
      res = res >> 1;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   222
    }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   223
    assert(res_offset >= l_offset, "just checking");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   224
    return MIN2(res_offset, r_offset);
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
  // skip over all word length 1-bit runs
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   227
  for (index++; index < r_index; index++) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   228
    res = map(index);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   229
    if (res != (uintptr_t)AllBits) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   230
      // found a 0, return the offset
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   231
      for (res_offset = index << LogBitsPerWord; res & 1;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   232
           res_offset++) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   233
        res = res >> 1;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   234
      }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   235
      assert(!(res & 1), "tautology; see loop condition");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   236
      assert(res_offset >= l_offset, "just checking");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   237
      return MIN2(res_offset, r_offset);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  }
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   240
  return r_offset;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   241
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   242
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   243
inline BitMap::idx_t
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   244
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
   245
                                                 idx_t r_offset) const
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
  verify_range(l_offset, r_offset);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   248
  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
   249
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   250
  if (l_offset == r_offset) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   251
    return l_offset;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   252
  }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   253
  idx_t   index = word_index(l_offset);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   254
  idx_t r_index = word_index(r_offset);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   255
  idx_t res_offset = l_offset;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   256
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   257
  // 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
   258
  idx_t res = map(index) >> bit_in_word(res_offset);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   259
  if (res != (uintptr_t)NoBits) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   260
    // find the position of the 1-bit
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   261
    for (; !(res & 1); res_offset++) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   262
      res = res >> 1;
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
    assert(res_offset >= l_offset &&
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   265
           res_offset < r_offset, "just checking");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   266
    return res_offset;
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
  // skip over all word length 0-bit runs
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   269
  for (index++; index < r_index; index++) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   270
    res = map(index);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   271
    if (res != (uintptr_t)NoBits) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   272
      // found a 1, return the offset
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   273
      for (res_offset = bit_index(index); !(res & 1); res_offset++) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   274
        res = res >> 1;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   275
      }
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   276
      assert(res & 1, "tautology; see loop condition");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   277
      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
   278
      return res_offset;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   279
    }
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 r_offset;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
}
1374
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
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   285
// 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
   286
// 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
   287
// 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
   288
// range.  Note:  end must not be 0.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   289
inline BitMap::bm_word_t
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   290
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
   291
  assert(end != 0, "does not work when end == 0");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   292
  assert(beg == end || word_index(beg) == word_index(end - 1),
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   293
         "must be a single-word range");
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   294
  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
   295
  if (bit_in_word(end) != 0) {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   296
    mask |= ~(bit_mask(end) - 1);       // high (left) bits
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
  return mask;
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   299
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   300
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   301
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
   302
  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
   303
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   304
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   305
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
   306
  memset(_map + beg, 0, (end - beg) * sizeof(uintptr_t));
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
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   309
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
   310
  idx_t bit_rounded_up = bit + (BitsPerWord - 1);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   311
  // Check for integer arithmetic overflow.
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   312
  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
   313
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   314
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   315
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
   316
                                          idx_t r_offset) const {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   317
  return get_next_one_offset_inline(l_offset, r_offset);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   318
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   319
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   320
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
   321
                                           idx_t r_offset) const {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   322
  return get_next_zero_offset_inline(l_offset, r_offset);
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   323
}
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   324
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   325
inline void BitMap2D::clear() {
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   326
  _map.clear();
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   327
}
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   328
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   329
#endif // SHARE_VM_UTILITIES_BITMAP_INLINE_HPP