8141496: BitMap set operations copy their other BitMap argument
Reviewed-by: mgerdin, tschatzl
--- a/hotspot/src/share/vm/utilities/bitMap.cpp Tue Apr 26 20:55:39 2016 +0200
+++ b/hotspot/src/share/vm/utilities/bitMap.cpp Wed Apr 27 08:48:39 2016 +0200
@@ -271,10 +271,10 @@
par_put_range_within_word(bit_index(end_full_word), end, value);
}
-bool BitMap::contains(const BitMap other) const {
+bool BitMap::contains(const BitMap& other) const {
assert(size() == other.size(), "must have same size");
- bm_word_t* dest_map = map();
- bm_word_t* other_map = other.map();
+ const bm_word_t* dest_map = map();
+ const bm_word_t* other_map = other.map();
idx_t size = size_in_words();
for (idx_t index = 0; index < size_in_words(); index++) {
bm_word_t word_union = dest_map[index] | other_map[index];
@@ -285,10 +285,10 @@
return true;
}
-bool BitMap::intersects(const BitMap other) const {
+bool BitMap::intersects(const BitMap& other) const {
assert(size() == other.size(), "must have same size");
- bm_word_t* dest_map = map();
- bm_word_t* other_map = other.map();
+ const bm_word_t* dest_map = map();
+ const bm_word_t* other_map = other.map();
idx_t size = size_in_words();
for (idx_t index = 0; index < size_in_words(); index++) {
if ((dest_map[index] & other_map[index]) != 0) return true;
@@ -297,10 +297,10 @@
return false;
}
-void BitMap::set_union(BitMap other) {
+void BitMap::set_union(const BitMap& other) {
assert(size() == other.size(), "must have same size");
bm_word_t* dest_map = map();
- bm_word_t* other_map = other.map();
+ const bm_word_t* other_map = other.map();
idx_t size = size_in_words();
for (idx_t index = 0; index < size_in_words(); index++) {
dest_map[index] = dest_map[index] | other_map[index];
@@ -308,10 +308,10 @@
}
-void BitMap::set_difference(BitMap other) {
+void BitMap::set_difference(const BitMap& other) {
assert(size() == other.size(), "must have same size");
bm_word_t* dest_map = map();
- bm_word_t* other_map = other.map();
+ const bm_word_t* other_map = other.map();
idx_t size = size_in_words();
for (idx_t index = 0; index < size_in_words(); index++) {
dest_map[index] = dest_map[index] & ~(other_map[index]);
@@ -319,10 +319,10 @@
}
-void BitMap::set_intersection(BitMap other) {
+void BitMap::set_intersection(const BitMap& other) {
assert(size() == other.size(), "must have same size");
bm_word_t* dest_map = map();
- bm_word_t* other_map = other.map();
+ const bm_word_t* other_map = other.map();
idx_t size = size_in_words();
for (idx_t index = 0; index < size; index++) {
dest_map[index] = dest_map[index] & other_map[index];
@@ -330,14 +330,14 @@
}
-void BitMap::set_intersection_at_offset(BitMap other, idx_t offset) {
+void BitMap::set_intersection_at_offset(const BitMap& other, idx_t offset) {
assert(other.size() >= offset, "offset not in range");
assert(other.size() - offset >= size(), "other not large enough");
// XXX Ideally, we would remove this restriction.
guarantee((offset % (sizeof(bm_word_t) * BitsPerByte)) == 0,
"Only handle aligned cases so far.");
bm_word_t* dest_map = map();
- bm_word_t* other_map = other.map();
+ const bm_word_t* other_map = other.map();
idx_t offset_word_ind = word_index(offset);
idx_t size = size_in_words();
for (idx_t index = 0; index < size; index++) {
@@ -345,11 +345,11 @@
}
}
-bool BitMap::set_union_with_result(BitMap other) {
+bool BitMap::set_union_with_result(const BitMap& other) {
assert(size() == other.size(), "must have same size");
bool changed = false;
bm_word_t* dest_map = map();
- bm_word_t* other_map = other.map();
+ const bm_word_t* other_map = other.map();
idx_t size = size_in_words();
for (idx_t index = 0; index < size; index++) {
idx_t temp = dest_map[index] | other_map[index];
@@ -360,11 +360,11 @@
}
-bool BitMap::set_difference_with_result(BitMap other) {
+bool BitMap::set_difference_with_result(const BitMap& other) {
assert(size() == other.size(), "must have same size");
bool changed = false;
bm_word_t* dest_map = map();
- bm_word_t* other_map = other.map();
+ const bm_word_t* other_map = other.map();
idx_t size = size_in_words();
for (idx_t index = 0; index < size; index++) {
bm_word_t temp = dest_map[index] & ~(other_map[index]);
@@ -375,11 +375,11 @@
}
-bool BitMap::set_intersection_with_result(BitMap other) {
+bool BitMap::set_intersection_with_result(const BitMap& other) {
assert(size() == other.size(), "must have same size");
bool changed = false;
bm_word_t* dest_map = map();
- bm_word_t* other_map = other.map();
+ const bm_word_t* other_map = other.map();
idx_t size = size_in_words();
for (idx_t index = 0; index < size; index++) {
bm_word_t orig = dest_map[index];
@@ -391,10 +391,10 @@
}
-void BitMap::set_from(BitMap other) {
+void BitMap::set_from(const BitMap& other) {
assert(size() == other.size(), "must have same size");
bm_word_t* dest_map = map();
- bm_word_t* other_map = other.map();
+ const bm_word_t* other_map = other.map();
idx_t size = size_in_words();
for (idx_t index = 0; index < size; index++) {
dest_map[index] = other_map[index];
@@ -402,10 +402,10 @@
}
-bool BitMap::is_same(BitMap other) {
+bool BitMap::is_same(const BitMap& other) {
assert(size() == other.size(), "must have same size");
bm_word_t* dest_map = map();
- bm_word_t* other_map = other.map();
+ const bm_word_t* other_map = other.map();
idx_t size = size_in_words();
for (idx_t index = 0; index < size; index++) {
if (dest_map[index] != other_map[index]) return false;
@@ -414,7 +414,7 @@
}
bool BitMap::is_full() const {
- bm_word_t* word = map();
+ const bm_word_t* word = map();
idx_t rest = size();
for (; rest >= (idx_t) BitsPerWord; rest -= BitsPerWord) {
if (*word != ~(bm_word_t)0) return false;
@@ -425,7 +425,7 @@
bool BitMap::is_empty() const {
- bm_word_t* word = map();
+ const bm_word_t* word = map();
idx_t rest = size();
for (; rest >= (idx_t) BitsPerWord; rest -= BitsPerWord) {
if (*word != 0) return false;
--- a/hotspot/src/share/vm/utilities/bitMap.hpp Tue Apr 26 20:55:39 2016 +0200
+++ b/hotspot/src/share/vm/utilities/bitMap.hpp Wed Apr 27 08:48:39 2016 +0200
@@ -70,11 +70,13 @@
static idx_t bit_index(idx_t word) { return word << LogBitsPerWord; }
// Return the array of bitmap words, or a specific word from it.
- bm_word_t* map() const { return _map; }
+ bm_word_t* map() { return _map; }
+ const bm_word_t* map() const { return _map; }
bm_word_t map(idx_t word) const { return _map[word]; }
// Return a pointer to the word containing the specified bit.
- bm_word_t* word_addr(idx_t bit) const { return map() + word_index(bit); }
+ bm_word_t* word_addr(idx_t bit) { return map() + word_index(bit); }
+ const bm_word_t* word_addr(idx_t bit) const { return map() + word_index(bit); }
// Set a word to a specified value or to all ones; clear a word.
void set_word (idx_t word, bm_word_t val) { _map[word] = val; }
@@ -237,19 +239,19 @@
idx_t count_one_bits() const;
// Set operations.
- void set_union(BitMap bits);
- void set_difference(BitMap bits);
- void set_intersection(BitMap bits);
+ void set_union(const BitMap& bits);
+ void set_difference(const BitMap& bits);
+ void set_intersection(const BitMap& bits);
// Returns true iff "this" is a superset of "bits".
- bool contains(const BitMap bits) const;
+ bool contains(const BitMap& bits) const;
// Returns true iff "this and "bits" have a non-empty intersection.
- bool intersects(const BitMap bits) const;
+ bool intersects(const BitMap& bits) const;
// Returns result of whether this map changed
// during the operation
- bool set_union_with_result(BitMap bits);
- bool set_difference_with_result(BitMap bits);
- bool set_intersection_with_result(BitMap bits);
+ bool set_union_with_result(const BitMap& bits);
+ bool set_difference_with_result(const BitMap& bits);
+ bool set_intersection_with_result(const BitMap& bits);
// Requires the submap of "bits" starting at offset to be at least as
// large as "this". Modifies "this" to be the intersection of its
@@ -258,11 +260,11 @@
// (For expedience, currently requires the offset to be aligned to the
// bitsize of a uintptr_t. This should go away in the future though it
// will probably remain a good case to optimize.)
- void set_intersection_at_offset(BitMap bits, idx_t offset);
+ void set_intersection_at_offset(const BitMap& bits, idx_t offset);
- void set_from(BitMap bits);
+ void set_from(const BitMap& bits);
- bool is_same(BitMap bits);
+ bool is_same(const BitMap& bits);
// Test if all bits are set or cleared
bool is_full() const;