Skip to content

Commit b3420ad

Browse files
author
Kostya Kortchinsky
committed
[scudo][standalone] Code tidying (NFC)
- 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
1 parent bc847b3 commit b3420ad

File tree

6 files changed

+19
-27
lines changed

6 files changed

+19
-27
lines changed

compiler-rt/lib/scudo/standalone/memtag.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ inline constexpr uptr archMemoryTagGranuleSize() { return 16; }
2828

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

31-
inline uint8_t extractTag(uptr Ptr) {
32-
return (Ptr >> 56) & 0xf;
33-
}
31+
inline uint8_t extractTag(uptr Ptr) { return (Ptr >> 56) & 0xf; }
3432

3533
#else
3634

@@ -82,7 +80,7 @@ inline void enableMemoryTagChecksTestOnly() {
8280
class ScopedDisableMemoryTagChecks {
8381
size_t PrevTCO;
8482

85-
public:
83+
public:
8684
ScopedDisableMemoryTagChecks() {
8785
__asm__ __volatile__(".arch_extension mte; mrs %0, tco; msr tco, #1"
8886
: "=r"(PrevTCO));
@@ -190,8 +188,8 @@ inline void resizeTaggedChunk(uptr OldPtr, uptr NewPtr, uptr BlockEnd) {
190188
191189
2:
192190
)"
193-
: [ Cur ] "+&r"(RoundOldPtr), [ End ] "+&r"(NewPtr)
194-
: [ BlockEnd ] "r"(BlockEnd)
191+
: [Cur] "+&r"(RoundOldPtr), [End] "+&r"(NewPtr)
192+
: [BlockEnd] "r"(BlockEnd)
195193
: "memory");
196194
}
197195

compiler-rt/lib/scudo/standalone/options.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ struct AtomicOptions {
4040
atomic_u32 Val;
4141

4242
public:
43-
Options load() const {
44-
return Options{atomic_load(&Val, memory_order_relaxed)};
45-
}
43+
Options load() const { return Options{atomic_load_relaxed(&Val)}; }
4644

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

5654
void setFillContentsMode(FillContentsMode FillContents) {
57-
u32 Opts = atomic_load(&Val, memory_order_relaxed), NewOpts;
55+
u32 Opts = atomic_load_relaxed(&Val), NewOpts;
5856
do {
5957
NewOpts = Opts;
6058
NewOpts &= ~(3U << static_cast<u32>(OptionBit::FillContents0of2));

compiler-rt/lib/scudo/standalone/primary32.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ class SizeClassAllocator32 {
190190
const s32 Interval =
191191
Max(Min(static_cast<s32>(Value), MaxReleaseToOsIntervalMs),
192192
MinReleaseToOsIntervalMs);
193-
atomic_store(&ReleaseToOsIntervalMs, Interval, memory_order_relaxed);
193+
atomic_store_relaxed(&ReleaseToOsIntervalMs, Interval);
194194
return true;
195195
}
196196
// Not supported by the Primary, but not an error either.
@@ -462,8 +462,7 @@ class SizeClassAllocator32 {
462462
}
463463

464464
if (!Force) {
465-
const s32 IntervalMs =
466-
atomic_load(&ReleaseToOsIntervalMs, memory_order_relaxed);
465+
const s32 IntervalMs = atomic_load_relaxed(&ReleaseToOsIntervalMs);
467466
if (IntervalMs < 0)
468467
return 0;
469468
if (Sci->ReleaseInfo.LastReleaseAtNs +

compiler-rt/lib/scudo/standalone/primary64.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ class SizeClassAllocator64 {
191191
const s32 Interval =
192192
Max(Min(static_cast<s32>(Value), MaxReleaseToOsIntervalMs),
193193
MinReleaseToOsIntervalMs);
194-
atomic_store(&ReleaseToOsIntervalMs, Interval, memory_order_relaxed);
194+
atomic_store_relaxed(&ReleaseToOsIntervalMs, Interval);
195195
return true;
196196
}
197197
// Not supported by the Primary, but not an error either.
@@ -470,8 +470,7 @@ class SizeClassAllocator64 {
470470
}
471471

472472
if (!Force) {
473-
const s32 IntervalMs =
474-
atomic_load(&ReleaseToOsIntervalMs, memory_order_relaxed);
473+
const s32 IntervalMs = atomic_load_relaxed(&ReleaseToOsIntervalMs);
475474
if (IntervalMs < 0)
476475
return 0;
477476
if (Region->ReleaseInfo.LastReleaseAtNs +

compiler-rt/lib/scudo/standalone/secondary.h

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class MapAllocatorCache {
9494
bool EntryCached = false;
9595
bool EmptyCache = false;
9696
const u64 Time = getMonotonicTime();
97-
const u32 MaxCount = atomic_load(&MaxEntriesCount, memory_order_relaxed);
97+
const u32 MaxCount = atomic_load_relaxed(&MaxEntriesCount);
9898
{
9999
ScopedLock L(Mutex);
100100
if (EntriesCount >= MaxCount) {
@@ -121,15 +121,14 @@ class MapAllocatorCache {
121121
s32 Interval;
122122
if (EmptyCache)
123123
empty();
124-
else if ((Interval = atomic_load(&ReleaseToOsIntervalMs,
125-
memory_order_relaxed)) >= 0)
124+
else if ((Interval = atomic_load_relaxed(&ReleaseToOsIntervalMs)) >= 0)
126125
releaseOlderThan(Time - static_cast<u64>(Interval) * 1000000);
127126
return EntryCached;
128127
}
129128

130129
bool retrieve(uptr Size, LargeBlock::Header **H) {
131130
const uptr PageSize = getPageSizeCached();
132-
const u32 MaxCount = atomic_load(&MaxEntriesCount, memory_order_relaxed);
131+
const u32 MaxCount = atomic_load_relaxed(&MaxEntriesCount);
133132
ScopedLock L(Mutex);
134133
if (EntriesCount == 0)
135134
return false;
@@ -154,26 +153,25 @@ class MapAllocatorCache {
154153
}
155154

156155
bool canCache(uptr Size) {
157-
return atomic_load(&MaxEntriesCount, memory_order_relaxed) != 0U &&
158-
Size <= atomic_load(&MaxEntrySize, memory_order_relaxed);
156+
return atomic_load_relaxed(&MaxEntriesCount) != 0U &&
157+
Size <= atomic_load_relaxed(&MaxEntrySize);
159158
}
160159

161160
bool setOption(Option O, sptr Value) {
162161
if (O == Option::ReleaseInterval) {
163162
const s32 Interval =
164163
Max(Min(static_cast<s32>(Value), MaxReleaseToOsIntervalMs),
165164
MinReleaseToOsIntervalMs);
166-
atomic_store(&ReleaseToOsIntervalMs, Interval, memory_order_relaxed);
165+
atomic_store_relaxed(&ReleaseToOsIntervalMs, Interval);
167166
return true;
168167
} else if (O == Option::MaxCacheEntriesCount) {
169168
const u32 MaxCount = static_cast<u32>(Value);
170169
if (MaxCount > EntriesArraySize)
171170
return false;
172-
atomic_store(&MaxEntriesCount, MaxCount, memory_order_relaxed);
171+
atomic_store_relaxed(&MaxEntriesCount, MaxCount);
173172
return true;
174173
} else if (O == Option::MaxCacheEntrySize) {
175-
atomic_store(&MaxEntrySize, static_cast<uptr>(Value),
176-
memory_order_relaxed);
174+
atomic_store_relaxed(&MaxEntrySize, static_cast<uptr>(Value));
177175
return true;
178176
}
179177
// Not supported by the Secondary Cache, but not an error either.

compiler-rt/lib/scudo/standalone/stack_depot.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class MurMur2HashBuilder {
2020
static const u32 R = 24;
2121
u32 H;
2222

23-
public:
23+
public:
2424
explicit MurMur2HashBuilder(u32 Init = 0) { H = Seed ^ Init; }
2525
void add(u32 K) {
2626
K *= M;

0 commit comments

Comments
 (0)