Commit d4b39acc authored by Jakob Gruber's avatar Jakob Gruber Committed by Commit Bot

[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: 's avatarClemens Backes <clemensb@chromium.org>
Auto-Submit: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#64667}
parent dcfc453e
......@@ -283,6 +283,8 @@ constexpr int kMaxRegularHeapObjectSize = (1 << (kPageSizeBits - 1));
constexpr int kBitsPerByte = 8;
constexpr int kBitsPerByteLog2 = 3;
constexpr int kBitsPerSystemPointer = kSystemPointerSize * kBitsPerByte;
constexpr int kBitsPerSystemPointerLog2 =
kSystemPointerSizeLog2 + kBitsPerByteLog2;
constexpr int kBitsPerInt = kIntSize * kBitsPerByte;
// IEEE 754 single precision floating point number bit layout.
......
......@@ -41,15 +41,13 @@ void BitVector::Iterator::Advance() {
}
int BitVector::Count() const {
if (data_length_ == 0) {
return base::bits::CountPopulation(data_.inline_);
} else {
int count = 0;
for (int i = 0; i < data_length_; i++) {
count += base::bits::CountPopulation(data_.ptr_[i]);
}
return count;
if (is_inline()) return base::bits::CountPopulation(data_.inline_);
int count = 0;
for (int i = 0; i < data_length_; i++) {
count += base::bits::CountPopulation(data_.ptr_[i]);
}
return count;
}
} // namespace internal
......
......@@ -66,8 +66,8 @@ class V8_EXPORT_PRIVATE BitVector : public ZoneObject {
};
static const int kDataLengthForInline = 1;
static const int kDataBits = kSystemPointerSize * 8;
static const int kDataBitShift = kSystemPointerSize == 8 ? 6 : 5;
static const int kDataBits = kBitsPerSystemPointer;
static const int kDataBitShift = kBitsPerSystemPointerLog2;
static const uintptr_t kOne = 1; // This saves some static_casts.
BitVector() : length_(0), data_length_(kDataLengthForInline), data_(0) {}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment