Commit 02a80f0d authored by Ulan Degenbaev's avatar Ulan Degenbaev Committed by Commit Bot

[heap] Refactor markbits atomics.

Change-Id: If0f80ceac9582f5bd0f9177db67b2a833fa8c8cd
Reviewed-on: https://chromium-review.googlesource.com/539418Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46010}
parent bbdf4b96
...@@ -16,9 +16,7 @@ class MarkBit { ...@@ -16,9 +16,7 @@ class MarkBit {
typedef uint32_t CellType; typedef uint32_t CellType;
STATIC_ASSERT(sizeof(CellType) == sizeof(base::Atomic32)); STATIC_ASSERT(sizeof(CellType) == sizeof(base::Atomic32));
inline MarkBit(base::Atomic32* cell, CellType mask) : cell_(cell) { inline MarkBit(CellType* cell, CellType mask) : cell_(cell), mask_(mask) {}
mask_ = static_cast<base::Atomic32>(mask);
}
#ifdef DEBUG #ifdef DEBUG
bool operator==(const MarkBit& other) { bool operator==(const MarkBit& other) {
...@@ -49,8 +47,8 @@ class MarkBit { ...@@ -49,8 +47,8 @@ class MarkBit {
template <AccessMode mode = AccessMode::NON_ATOMIC> template <AccessMode mode = AccessMode::NON_ATOMIC>
inline bool Clear(); inline bool Clear();
base::Atomic32* cell_; CellType* cell_;
base::Atomic32 mask_; CellType mask_;
friend class IncrementalMarking; friend class IncrementalMarking;
friend class ConcurrentMarkingMarkbits; friend class ConcurrentMarkingMarkbits;
...@@ -59,52 +57,36 @@ class MarkBit { ...@@ -59,52 +57,36 @@ class MarkBit {
template <> template <>
inline bool MarkBit::Set<AccessMode::NON_ATOMIC>() { inline bool MarkBit::Set<AccessMode::NON_ATOMIC>() {
base::Atomic32 old_value = *cell_; CellType old_value = *cell_;
*cell_ = old_value | mask_; *cell_ = old_value | mask_;
return (old_value & mask_) == 0; return (old_value & mask_) == 0;
} }
template <> template <>
inline bool MarkBit::Set<AccessMode::ATOMIC>() { inline bool MarkBit::Set<AccessMode::ATOMIC>() {
base::Atomic32 old_value; return base::AsAtomic32::SetBits(cell_, mask_, mask_);
base::Atomic32 new_value;
do {
old_value = base::Relaxed_Load(cell_);
if (old_value & mask_) return false;
new_value = old_value | mask_;
} while (base::Release_CompareAndSwap(cell_, old_value, new_value) !=
old_value);
return true;
} }
template <> template <>
inline bool MarkBit::Get<AccessMode::NON_ATOMIC>() { inline bool MarkBit::Get<AccessMode::NON_ATOMIC>() {
return (base::Relaxed_Load(cell_) & mask_) != 0; return (*cell_ & mask_) != 0;
} }
template <> template <>
inline bool MarkBit::Get<AccessMode::ATOMIC>() { inline bool MarkBit::Get<AccessMode::ATOMIC>() {
return (base::Acquire_Load(cell_) & mask_) != 0; return (base::AsAtomic32::Acquire_Load(cell_) & mask_) != 0;
} }
template <> template <>
inline bool MarkBit::Clear<AccessMode::NON_ATOMIC>() { inline bool MarkBit::Clear<AccessMode::NON_ATOMIC>() {
base::Atomic32 old_value = *cell_; CellType old_value = *cell_;
*cell_ = old_value & ~mask_; *cell_ = old_value & ~mask_;
return (old_value & mask_) == mask_; return (old_value & mask_) == mask_;
} }
template <> template <>
inline bool MarkBit::Clear<AccessMode::ATOMIC>() { inline bool MarkBit::Clear<AccessMode::ATOMIC>() {
base::Atomic32 old_value; return base::AsAtomic32::SetBits(cell_, 0u, mask_);
base::Atomic32 new_value;
do {
old_value = base::Relaxed_Load(cell_);
if (!(old_value & mask_)) return false;
new_value = old_value & ~mask_;
} while (base::Release_CompareAndSwap(cell_, old_value, new_value) !=
old_value);
return true;
} }
// Bitmap is a sequence of cells each containing fixed number of bits. // Bitmap is a sequence of cells each containing fixed number of bits.
...@@ -160,7 +142,7 @@ class V8_EXPORT_PRIVATE Bitmap { ...@@ -160,7 +142,7 @@ class V8_EXPORT_PRIVATE Bitmap {
inline MarkBit MarkBitFromIndex(uint32_t index) { inline MarkBit MarkBitFromIndex(uint32_t index) {
MarkBit::CellType mask = 1u << IndexInCell(index); MarkBit::CellType mask = 1u << IndexInCell(index);
MarkBit::CellType* cell = this->cells() + (index >> kBitsPerCellLog2); MarkBit::CellType* cell = this->cells() + (index >> kBitsPerCellLog2);
return MarkBit(reinterpret_cast<base::Atomic32*>(cell), mask); return MarkBit(cell, mask);
} }
void Clear(); void Clear();
...@@ -205,15 +187,7 @@ inline void Bitmap::SetBitsInCell<AccessMode::NON_ATOMIC>(uint32_t cell_index, ...@@ -205,15 +187,7 @@ inline void Bitmap::SetBitsInCell<AccessMode::NON_ATOMIC>(uint32_t cell_index,
template <> template <>
inline void Bitmap::SetBitsInCell<AccessMode::ATOMIC>(uint32_t cell_index, inline void Bitmap::SetBitsInCell<AccessMode::ATOMIC>(uint32_t cell_index,
uint32_t mask) { uint32_t mask) {
base::Atomic32* cell = base::AsAtomic32::SetBits(cells() + cell_index, mask, mask);
reinterpret_cast<base::Atomic32*>(cells() + cell_index);
base::Atomic32 old_value;
base::Atomic32 new_value;
do {
old_value = base::Relaxed_Load(cell);
new_value = old_value | mask;
} while (base::Release_CompareAndSwap(cell, old_value, new_value) !=
old_value);
} }
template <> template <>
...@@ -225,15 +199,7 @@ inline void Bitmap::ClearBitsInCell<AccessMode::NON_ATOMIC>(uint32_t cell_index, ...@@ -225,15 +199,7 @@ inline void Bitmap::ClearBitsInCell<AccessMode::NON_ATOMIC>(uint32_t cell_index,
template <> template <>
inline void Bitmap::ClearBitsInCell<AccessMode::ATOMIC>(uint32_t cell_index, inline void Bitmap::ClearBitsInCell<AccessMode::ATOMIC>(uint32_t cell_index,
uint32_t mask) { uint32_t mask) {
base::Atomic32* cell = base::AsAtomic32::SetBits(cells() + cell_index, 0u, mask);
reinterpret_cast<base::Atomic32*>(cells() + cell_index);
base::Atomic32 old_value;
base::Atomic32 new_value;
do {
old_value = base::Relaxed_Load(cell);
new_value = old_value & ~mask;
} while (base::Release_CompareAndSwap(cell, old_value, new_value) !=
old_value);
} }
class Marking : public AllStatic { class Marking : public AllStatic {
......
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