Commit 5f63297c authored by Omer Katz's avatar Omer Katz Committed by Commit Bot

heap: Replace ClearMemoryAtomically implementation with AtomicMemzero

Bug: 986235
Change-Id: Ic8553f6c9858997d6db493c9a12e016bd84fb55f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2148788
Commit-Queue: Omer Katz <omerkatz@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarMichael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#760584}
parent 7e85f39a
...@@ -43,24 +43,14 @@ template <typename T> ...@@ -43,24 +43,14 @@ template <typename T>
struct HashTraits; struct HashTraits;
namespace { namespace {
template <typename T, bool use_atomic_writes = IsTraceable<T>::value> template <typename T, bool = IsTraceable<T>::value>
void ClearMemoryAtomically(T* slot, size_t size) { struct ClearMemoryAtomicallyIfNeeded {
size_t* address = reinterpret_cast<size_t*>(slot); static void Clear(T* slot) { memset(static_cast<void*>(slot), 0, sizeof(T)); }
// This method is called for clearing hash table entires that are removed. In };
// case Oilpan concurrent marking is tracing the hash table at the same time, template <typename T>
// there might be a data race between the marker reading the entry and zeroing struct ClearMemoryAtomicallyIfNeeded<T, true> {
// the entry. Using atomic reads here resolves any possible races. static void Clear(T* slot) { AtomicMemzero<sizeof(T)>(slot); }
// Note that sizeof(T) might not be a multiple of sizeof(size_t). The last };
// sizeof(T)%sizeof(size_t) bytes don't require atomic write as it cannot hold
// a pointer (i.e it will not be traceable).
if (use_atomic_writes) {
for (; size >= sizeof(size_t); size -= sizeof(size_t), ++address) {
WTF::AsAtomicPtr(address)->store(0, std::memory_order_relaxed);
}
}
DCHECK(!use_atomic_writes || (size < sizeof(size_t)));
memset(address, 0, size);
}
} // namespace } // namespace
template <typename T> template <typename T>
...@@ -395,7 +385,8 @@ struct PairHashTraits ...@@ -395,7 +385,8 @@ struct PairHashTraits
// hold as they did at the initial allocation. Therefore we zero the // hold as they did at the initial allocation. Therefore we zero the
// value part of the slot here for GC collections. // value part of the slot here for GC collections.
if (zero_value) { if (zero_value) {
ClearMemoryAtomically(&slot.second, sizeof(slot.second)); ClearMemoryAtomicallyIfNeeded<typename SecondTraits::TraitType>::Clear(
&slot.second);
} }
} }
static bool IsDeletedValue(const TraitType& value) { static bool IsDeletedValue(const TraitType& value) {
...@@ -468,7 +459,8 @@ struct KeyValuePairHashTraits ...@@ -468,7 +459,8 @@ struct KeyValuePairHashTraits
KeyTraits::ConstructDeletedValue(slot.key, zero_value); KeyTraits::ConstructDeletedValue(slot.key, zero_value);
// See similar code in this file for why we need to do this. // See similar code in this file for why we need to do this.
if (zero_value) { if (zero_value) {
ClearMemoryAtomically(&slot.value, sizeof(slot.value)); ClearMemoryAtomicallyIfNeeded<typename ValueTraits::TraitType>::Clear(
&slot.value);
} }
} }
static bool IsDeletedValue(const TraitType& value) { static bool IsDeletedValue(const TraitType& value) {
......
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