Skip to content

Commit d4b39ac

Browse files
schuayCommit Bot
authored andcommitted
[utils] Fix BitVector::Count with an inline backing store
The condition to detect an inline backing store was wrong and we would try to access the heap-allocated store even for inline stores. Drive-by: Use kBitsPerSystemPointer and the new kBitsPerSystemPointerLog2 constants. Change-Id: I19d0245ae82642a788c967534ab2a84464d56a67 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1890093 Commit-Queue: Jakob Gruber <jgruber@chromium.org> Reviewed-by: Clemens Backes <clemensb@chromium.org> Auto-Submit: Jakob Gruber <jgruber@chromium.org> Cr-Commit-Position: refs/heads/master@{#64667}
1 parent dcfc453 commit d4b39ac

3 files changed

Lines changed: 10 additions & 10 deletions

File tree

src/common/globals.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,8 @@ constexpr int kMaxRegularHeapObjectSize = (1 << (kPageSizeBits - 1));
283283
constexpr int kBitsPerByte = 8;
284284
constexpr int kBitsPerByteLog2 = 3;
285285
constexpr int kBitsPerSystemPointer = kSystemPointerSize * kBitsPerByte;
286+
constexpr int kBitsPerSystemPointerLog2 =
287+
kSystemPointerSizeLog2 + kBitsPerByteLog2;
286288
constexpr int kBitsPerInt = kIntSize * kBitsPerByte;
287289

288290
// IEEE 754 single precision floating point number bit layout.

src/utils/bit-vector.cc

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,13 @@ void BitVector::Iterator::Advance() {
4141
}
4242

4343
int BitVector::Count() const {
44-
if (data_length_ == 0) {
45-
return base::bits::CountPopulation(data_.inline_);
46-
} else {
47-
int count = 0;
48-
for (int i = 0; i < data_length_; i++) {
49-
count += base::bits::CountPopulation(data_.ptr_[i]);
50-
}
51-
return count;
44+
if (is_inline()) return base::bits::CountPopulation(data_.inline_);
45+
46+
int count = 0;
47+
for (int i = 0; i < data_length_; i++) {
48+
count += base::bits::CountPopulation(data_.ptr_[i]);
5249
}
50+
return count;
5351
}
5452

5553
} // namespace internal

src/utils/bit-vector.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ class V8_EXPORT_PRIVATE BitVector : public ZoneObject {
6666
};
6767

6868
static const int kDataLengthForInline = 1;
69-
static const int kDataBits = kSystemPointerSize * 8;
70-
static const int kDataBitShift = kSystemPointerSize == 8 ? 6 : 5;
69+
static const int kDataBits = kBitsPerSystemPointer;
70+
static const int kDataBitShift = kBitsPerSystemPointerLog2;
7171
static const uintptr_t kOne = 1; // This saves some static_casts.
7272

7373
BitVector() : length_(0), data_length_(kDataLengthForInline), data_(0) {}

0 commit comments

Comments
 (0)