[compiler-rt] dab7bda - scudo: Delete unused class ScudoByteMap. NFCI.

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 6 09:30:42 PST 2020


Author: Peter Collingbourne
Date: 2020-02-06T09:30:24-08:00
New Revision: dab7bdad049221113ccf8c8ed9f7ead98809cef1

URL: https://github.com/llvm/llvm-project/commit/dab7bdad049221113ccf8c8ed9f7ead98809cef1
DIFF: https://github.com/llvm/llvm-project/commit/dab7bdad049221113ccf8c8ed9f7ead98809cef1.diff

LOG: scudo: Delete unused class ScudoByteMap. NFCI.

The class is only used in SizeClassAllocator32 in 64-bit mode, but we don't
use that class in 64-bit mode.

Differential Revision: https://reviews.llvm.org/D74099

Added: 
    

Modified: 
    compiler-rt/lib/scudo/standalone/bytemap.h
    compiler-rt/lib/scudo/standalone/primary32.h
    compiler-rt/lib/scudo/standalone/tests/bytemap_test.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/scudo/standalone/bytemap.h b/compiler-rt/lib/scudo/standalone/bytemap.h
index a03a0c471062..b3582a5a04d2 100644
--- a/compiler-rt/lib/scudo/standalone/bytemap.h
+++ b/compiler-rt/lib/scudo/standalone/bytemap.h
@@ -41,77 +41,6 @@ template <uptr Size> class FlatByteMap {
   u8 *Map;
 };
 
-template <uptr Level1Size, uptr Level2Size> class TwoLevelByteMap {
-public:
-  void initLinkerInitialized() {
-    Level1Map = reinterpret_cast<atomic_uptr *>(
-        map(nullptr, sizeof(atomic_uptr) * Level1Size, "scudo:bytemap"));
-  }
-  void init() {
-    Mutex.init();
-    initLinkerInitialized();
-  }
-
-  void reset() {
-    for (uptr I = 0; I < Level1Size; I++) {
-      u8 *P = get(I);
-      if (!P)
-        continue;
-      unmap(P, Level2Size);
-    }
-    memset(Level1Map, 0, sizeof(atomic_uptr) * Level1Size);
-  }
-
-  void unmapTestOnly() {
-    reset();
-    unmap(reinterpret_cast<void *>(Level1Map),
-          sizeof(atomic_uptr) * Level1Size);
-  }
-
-  uptr size() const { return Level1Size * Level2Size; }
-
-  void set(uptr Index, u8 Value) {
-    DCHECK_LT(Index, Level1Size * Level2Size);
-    u8 *Level2Map = getOrCreate(Index / Level2Size);
-    DCHECK_EQ(0U, Level2Map[Index % Level2Size]);
-    Level2Map[Index % Level2Size] = Value;
-  }
-
-  u8 operator[](uptr Index) const {
-    DCHECK_LT(Index, Level1Size * Level2Size);
-    u8 *Level2Map = get(Index / Level2Size);
-    if (!Level2Map)
-      return 0;
-    return Level2Map[Index % Level2Size];
-  }
-
-  void disable() { Mutex.lock(); }
-  void enable() { Mutex.unlock(); }
-
-private:
-  u8 *get(uptr Index) const {
-    DCHECK_LT(Index, Level1Size);
-    return reinterpret_cast<u8 *>(
-        atomic_load(&Level1Map[Index], memory_order_acquire));
-  }
-
-  u8 *getOrCreate(uptr Index) {
-    u8 *Res = get(Index);
-    if (!Res) {
-      ScopedLock L(Mutex);
-      if (!(Res = get(Index))) {
-        Res = reinterpret_cast<u8 *>(map(nullptr, Level2Size, "scudo:bytemap"));
-        atomic_store(&Level1Map[Index], reinterpret_cast<uptr>(Res),
-                     memory_order_release);
-      }
-    }
-    return Res;
-  }
-
-  atomic_uptr *Level1Map;
-  HybridMutex Mutex;
-};
-
 } // namespace scudo
 
 #endif // SCUDO_BYTEMAP_H_

diff  --git a/compiler-rt/lib/scudo/standalone/primary32.h b/compiler-rt/lib/scudo/standalone/primary32.h
index ab7a1f3eb8e3..50f6438ed38c 100644
--- a/compiler-rt/lib/scudo/standalone/primary32.h
+++ b/compiler-rt/lib/scudo/standalone/primary32.h
@@ -191,11 +191,7 @@ template <class SizeClassMapT, uptr RegionSizeLog> class SizeClassAllocator32 {
   static const uptr NumClasses = SizeClassMap::NumClasses;
   static const uptr RegionSize = 1UL << RegionSizeLog;
   static const uptr NumRegions = SCUDO_MMAP_RANGE_SIZE >> RegionSizeLog;
-#if SCUDO_WORDSIZE == 32U
   typedef FlatByteMap<NumRegions> ByteMap;
-#else
-  typedef TwoLevelByteMap<(NumRegions >> 12), 1UL << 12> ByteMap;
-#endif
 
   struct SizeClassStats {
     uptr PoppedBlocks;

diff  --git a/compiler-rt/lib/scudo/standalone/tests/bytemap_test.cpp b/compiler-rt/lib/scudo/standalone/tests/bytemap_test.cpp
index 7db7feb6accd..4034b108fab9 100644
--- a/compiler-rt/lib/scudo/standalone/tests/bytemap_test.cpp
+++ b/compiler-rt/lib/scudo/standalone/tests/bytemap_test.cpp
@@ -31,45 +31,3 @@ TEST(ScudoByteMapTest, FlatByteMap) {
   testMap(Map, Size);
   Map.unmapTestOnly();
 }
-
-TEST(ScudoByteMapTest, TwoLevelByteMap) {
-  const scudo::uptr Size1 = 1U << 6, Size2 = 1U << 12;
-  scudo::TwoLevelByteMap<Size1, Size2> Map;
-  testMap(Map, Size1 * Size2);
-  Map.unmapTestOnly();
-}
-
-using TestByteMap = scudo::TwoLevelByteMap<1U << 12, 1U << 13>;
-
-struct TestByteMapParam {
-  TestByteMap *Map;
-  scudo::uptr Shard;
-  scudo::uptr NumberOfShards;
-};
-
-void *populateByteMap(void *Param) {
-  TestByteMapParam *P = reinterpret_cast<TestByteMapParam *>(Param);
-  for (scudo::uptr I = P->Shard; I < P->Map->size(); I += P->NumberOfShards) {
-    scudo::u8 V = static_cast<scudo::u8>((I % 100) + 1);
-    P->Map->set(I, V);
-    EXPECT_EQ((*P->Map)[I], V);
-  }
-  return 0;
-}
-
-TEST(ScudoByteMapTest, ThreadedTwoLevelByteMap) {
-  TestByteMap Map;
-  Map.init();
-  static const scudo::uptr NumberOfThreads = 16U;
-  pthread_t T[NumberOfThreads];
-  TestByteMapParam P[NumberOfThreads];
-  for (scudo::uptr I = 0; I < NumberOfThreads; I++) {
-    P[I].Map = ⤅
-    P[I].Shard = I;
-    P[I].NumberOfShards = NumberOfThreads;
-    pthread_create(&T[I], 0, populateByteMap, &P[I]);
-  }
-  for (scudo::uptr I = 0; I < NumberOfThreads; I++)
-    pthread_join(T[I], 0);
-  Map.unmapTestOnly();
-}


        


More information about the llvm-commits mailing list