Skip to content

Commit

Permalink
[scudo][standalone] Code tidying (NFC)
Browse files Browse the repository at this point in the history
- we have clutter-reducing helpers for relaxed atomics that were barely
  used, use them everywhere we can
- clang-format everything with a recent version

Differential Revision: https://reviews.llvm.org/D90649
  • Loading branch information
Kostya Kortchinsky committed Nov 3, 2020
1 parent bc847b3 commit b3420ad
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 27 deletions.
10 changes: 4 additions & 6 deletions compiler-rt/lib/scudo/standalone/memtag.h
Expand Up @@ -28,9 +28,7 @@ inline constexpr uptr archMemoryTagGranuleSize() { return 16; }

inline uptr untagPointer(uptr Ptr) { return Ptr & ((1ULL << 56) - 1); }

inline uint8_t extractTag(uptr Ptr) {
return (Ptr >> 56) & 0xf;
}
inline uint8_t extractTag(uptr Ptr) { return (Ptr >> 56) & 0xf; }

#else

Expand Down Expand Up @@ -82,7 +80,7 @@ inline void enableMemoryTagChecksTestOnly() {
class ScopedDisableMemoryTagChecks {
size_t PrevTCO;

public:
public:
ScopedDisableMemoryTagChecks() {
__asm__ __volatile__(".arch_extension mte; mrs %0, tco; msr tco, #1"
: "=r"(PrevTCO));
Expand Down Expand Up @@ -190,8 +188,8 @@ inline void resizeTaggedChunk(uptr OldPtr, uptr NewPtr, uptr BlockEnd) {
2:
)"
: [ Cur ] "+&r"(RoundOldPtr), [ End ] "+&r"(NewPtr)
: [ BlockEnd ] "r"(BlockEnd)
: [Cur] "+&r"(RoundOldPtr), [End] "+&r"(NewPtr)
: [BlockEnd] "r"(BlockEnd)
: "memory");
}

Expand Down
6 changes: 2 additions & 4 deletions compiler-rt/lib/scudo/standalone/options.h
Expand Up @@ -40,9 +40,7 @@ struct AtomicOptions {
atomic_u32 Val;

public:
Options load() const {
return Options{atomic_load(&Val, memory_order_relaxed)};
}
Options load() const { return Options{atomic_load_relaxed(&Val)}; }

void clear(OptionBit Opt) {
atomic_fetch_and(&Val, ~(1U << static_cast<u32>(Opt)),
Expand All @@ -54,7 +52,7 @@ struct AtomicOptions {
}

void setFillContentsMode(FillContentsMode FillContents) {
u32 Opts = atomic_load(&Val, memory_order_relaxed), NewOpts;
u32 Opts = atomic_load_relaxed(&Val), NewOpts;
do {
NewOpts = Opts;
NewOpts &= ~(3U << static_cast<u32>(OptionBit::FillContents0of2));
Expand Down
5 changes: 2 additions & 3 deletions compiler-rt/lib/scudo/standalone/primary32.h
Expand Up @@ -190,7 +190,7 @@ class SizeClassAllocator32 {
const s32 Interval =
Max(Min(static_cast<s32>(Value), MaxReleaseToOsIntervalMs),
MinReleaseToOsIntervalMs);
atomic_store(&ReleaseToOsIntervalMs, Interval, memory_order_relaxed);
atomic_store_relaxed(&ReleaseToOsIntervalMs, Interval);
return true;
}
// Not supported by the Primary, but not an error either.
Expand Down Expand Up @@ -462,8 +462,7 @@ class SizeClassAllocator32 {
}

if (!Force) {
const s32 IntervalMs =
atomic_load(&ReleaseToOsIntervalMs, memory_order_relaxed);
const s32 IntervalMs = atomic_load_relaxed(&ReleaseToOsIntervalMs);
if (IntervalMs < 0)
return 0;
if (Sci->ReleaseInfo.LastReleaseAtNs +
Expand Down
5 changes: 2 additions & 3 deletions compiler-rt/lib/scudo/standalone/primary64.h
Expand Up @@ -191,7 +191,7 @@ class SizeClassAllocator64 {
const s32 Interval =
Max(Min(static_cast<s32>(Value), MaxReleaseToOsIntervalMs),
MinReleaseToOsIntervalMs);
atomic_store(&ReleaseToOsIntervalMs, Interval, memory_order_relaxed);
atomic_store_relaxed(&ReleaseToOsIntervalMs, Interval);
return true;
}
// Not supported by the Primary, but not an error either.
Expand Down Expand Up @@ -470,8 +470,7 @@ class SizeClassAllocator64 {
}

if (!Force) {
const s32 IntervalMs =
atomic_load(&ReleaseToOsIntervalMs, memory_order_relaxed);
const s32 IntervalMs = atomic_load_relaxed(&ReleaseToOsIntervalMs);
if (IntervalMs < 0)
return 0;
if (Region->ReleaseInfo.LastReleaseAtNs +
Expand Down
18 changes: 8 additions & 10 deletions compiler-rt/lib/scudo/standalone/secondary.h
Expand Up @@ -94,7 +94,7 @@ class MapAllocatorCache {
bool EntryCached = false;
bool EmptyCache = false;
const u64 Time = getMonotonicTime();
const u32 MaxCount = atomic_load(&MaxEntriesCount, memory_order_relaxed);
const u32 MaxCount = atomic_load_relaxed(&MaxEntriesCount);
{
ScopedLock L(Mutex);
if (EntriesCount >= MaxCount) {
Expand All @@ -121,15 +121,14 @@ class MapAllocatorCache {
s32 Interval;
if (EmptyCache)
empty();
else if ((Interval = atomic_load(&ReleaseToOsIntervalMs,
memory_order_relaxed)) >= 0)
else if ((Interval = atomic_load_relaxed(&ReleaseToOsIntervalMs)) >= 0)
releaseOlderThan(Time - static_cast<u64>(Interval) * 1000000);
return EntryCached;
}

bool retrieve(uptr Size, LargeBlock::Header **H) {
const uptr PageSize = getPageSizeCached();
const u32 MaxCount = atomic_load(&MaxEntriesCount, memory_order_relaxed);
const u32 MaxCount = atomic_load_relaxed(&MaxEntriesCount);
ScopedLock L(Mutex);
if (EntriesCount == 0)
return false;
Expand All @@ -154,26 +153,25 @@ class MapAllocatorCache {
}

bool canCache(uptr Size) {
return atomic_load(&MaxEntriesCount, memory_order_relaxed) != 0U &&
Size <= atomic_load(&MaxEntrySize, memory_order_relaxed);
return atomic_load_relaxed(&MaxEntriesCount) != 0U &&
Size <= atomic_load_relaxed(&MaxEntrySize);
}

bool setOption(Option O, sptr Value) {
if (O == Option::ReleaseInterval) {
const s32 Interval =
Max(Min(static_cast<s32>(Value), MaxReleaseToOsIntervalMs),
MinReleaseToOsIntervalMs);
atomic_store(&ReleaseToOsIntervalMs, Interval, memory_order_relaxed);
atomic_store_relaxed(&ReleaseToOsIntervalMs, Interval);
return true;
} else if (O == Option::MaxCacheEntriesCount) {
const u32 MaxCount = static_cast<u32>(Value);
if (MaxCount > EntriesArraySize)
return false;
atomic_store(&MaxEntriesCount, MaxCount, memory_order_relaxed);
atomic_store_relaxed(&MaxEntriesCount, MaxCount);
return true;
} else if (O == Option::MaxCacheEntrySize) {
atomic_store(&MaxEntrySize, static_cast<uptr>(Value),
memory_order_relaxed);
atomic_store_relaxed(&MaxEntrySize, static_cast<uptr>(Value));
return true;
}
// Not supported by the Secondary Cache, but not an error either.
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/scudo/standalone/stack_depot.h
Expand Up @@ -20,7 +20,7 @@ class MurMur2HashBuilder {
static const u32 R = 24;
u32 H;

public:
public:
explicit MurMur2HashBuilder(u32 Init = 0) { H = Seed ^ Init; }
void add(u32 K) {
K *= M;
Expand Down

0 comments on commit b3420ad

Please sign in to comment.