diff --git a/compiler-rt/lib/scudo/standalone/bytemap.h b/compiler-rt/lib/scudo/standalone/bytemap.h --- a/compiler-rt/lib/scudo/standalone/bytemap.h +++ b/compiler-rt/lib/scudo/standalone/bytemap.h @@ -41,77 +41,6 @@ u8 *Map; }; -template class TwoLevelByteMap { -public: - void initLinkerInitialized() { - Level1Map = reinterpret_cast( - 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(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( - 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(map(nullptr, Level2Size, "scudo:bytemap")); - atomic_store(&Level1Map[Index], reinterpret_cast(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 --- a/compiler-rt/lib/scudo/standalone/primary32.h +++ b/compiler-rt/lib/scudo/standalone/primary32.h @@ -191,11 +191,7 @@ 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 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 --- a/compiler-rt/lib/scudo/standalone/tests/bytemap_test.cpp +++ b/compiler-rt/lib/scudo/standalone/tests/bytemap_test.cpp @@ -31,45 +31,3 @@ testMap(Map, Size); Map.unmapTestOnly(); } - -TEST(ScudoByteMapTest, TwoLevelByteMap) { - const scudo::uptr Size1 = 1U << 6, Size2 = 1U << 12; - scudo::TwoLevelByteMap 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(Param); - for (scudo::uptr I = P->Shard; I < P->Map->size(); I += P->NumberOfShards) { - scudo::u8 V = static_cast((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(); -}