Skip to content

Commit

Permalink
Bug 1477626 - Use mozilla::HashTable instead of JS::HashTable in DMD.…
Browse files Browse the repository at this point in the history
… r=erahm

Also use mozilla::HashNumber where appropriate.

MozReview-Commit-ID: BTq0XDS5UfQ

--HG--
extra : rebase_source : 28f45a9b27e831e99620a2b575f373003f1301f2
  • Loading branch information
nnethercote committed Jul 26, 2018
1 parent 234016c commit 6998f46
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions memory/replace/dmd/DMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,17 @@
#endif

#include "nscore.h"
#include "mozilla/StackWalk.h"

#include "js/HashTable.h"
#include "js/Vector.h"

#include "mozilla/Assertions.h"
#include "mozilla/FastBernoulliTrial.h"
#include "mozilla/HashFunctions.h"
#include "mozilla/HashTable.h"
#include "mozilla/IntegerPrintfMacros.h"
#include "mozilla/JSONWriter.h"
#include "mozilla/Likely.h"
#include "mozilla/MemoryReporting.h"
#include "mozilla/StackWalk.h"
#include "mozilla/Vector.h"

// CodeAddressService is defined entirely in the header, so this does not make
// DMD depend on XPCOM's object file.
Expand Down Expand Up @@ -96,8 +95,8 @@ static malloc_table_t gMallocTable;
//
// - Direct allocations (the easy case).
//
// - Indirect allocations in js::{Vector,HashSet,HashMap} -- this class serves
// as their AllocPolicy.
// - Indirect allocations in mozilla::{Vector,HashSet,HashMap} -- this class
// serves as their AllocPolicy.
//
// - Other indirect allocations (e.g. MozStackWalk) -- see the comments on
// Thread::mBlockIntercepts and in replace_malloc for how these work.
Expand Down Expand Up @@ -162,15 +161,13 @@ class InfallibleAllocPolicy
return p;
}

// This realloc_ is the one we use for direct reallocs within DMD.
static void* realloc_(void* aPtr, size_t aNewSize)
{
void* p = gMallocTable.realloc(aPtr, aNewSize);
ExitOnFailure(p);
return p;
}

// This realloc_ is required for this to be a JS container AllocPolicy.
template <typename T>
static T* pod_realloc(T* aPtr, size_t aOldSize, size_t aNewSize)
{
Expand Down Expand Up @@ -621,7 +618,7 @@ class StringTable
{
typedef const char* Lookup;

static uint32_t hash(const char* const& aS)
static mozilla::HashNumber hash(const char* const& aS)
{
return HashString(aS);
}
Expand All @@ -632,7 +629,8 @@ class StringTable
}
};

typedef js::HashSet<const char*, StringHasher, InfallibleAllocPolicy> StringHashSet;
typedef mozilla::HashSet<const char*, StringHasher, InfallibleAllocPolicy>
StringHashSet;

StringHashSet mSet;
};
Expand Down Expand Up @@ -693,7 +691,7 @@ class StackTrace

typedef StackTrace* Lookup;

static uint32_t hash(const StackTrace* const& aSt)
static mozilla::HashNumber hash(const StackTrace* const& aSt)
{
return mozilla::HashBytes(aSt->mPcs, aSt->Size());
}
Expand All @@ -717,19 +715,21 @@ class StackTrace
}
};

typedef js::HashSet<StackTrace*, StackTrace, InfallibleAllocPolicy>
typedef mozilla::HashSet<StackTrace*, StackTrace, InfallibleAllocPolicy>
StackTraceTable;
static StackTraceTable* gStackTraceTable = nullptr;

typedef js::HashSet<const StackTrace*, js::DefaultHasher<const StackTrace*>,
InfallibleAllocPolicy>
typedef mozilla::HashSet<const StackTrace*,
mozilla::DefaultHasher<const StackTrace*>,
InfallibleAllocPolicy>
StackTraceSet;

typedef js::HashSet<const void*, js::DefaultHasher<const void*>,
InfallibleAllocPolicy>
typedef mozilla::HashSet<const void*, mozilla::DefaultHasher<const void*>,
InfallibleAllocPolicy>
PointerSet;
typedef js::HashMap<const void*, uint32_t, js::DefaultHasher<const void*>,
InfallibleAllocPolicy>
typedef mozilla::HashMap<const void*, uint32_t,
mozilla::DefaultHasher<const void*>,
InfallibleAllocPolicy>
PointerIdMap;

// We won't GC the stack trace table until it this many elements.
Expand Down Expand Up @@ -992,7 +992,7 @@ class LiveBlock

typedef const void* Lookup;

static uint32_t hash(const void* const& aPtr)
static mozilla::HashNumber hash(const void* const& aPtr)
{
return mozilla::HashGeneric(aPtr);
}
Expand All @@ -1004,15 +1004,16 @@ class LiveBlock
};

// A table of live blocks where the lookup key is the block address.
typedef js::HashSet<LiveBlock, LiveBlock, InfallibleAllocPolicy> LiveBlockTable;
typedef mozilla::HashSet<LiveBlock, LiveBlock, InfallibleAllocPolicy>
LiveBlockTable;
static LiveBlockTable* gLiveBlockTable = nullptr;

class AggregatedLiveBlockHashPolicy
{
public:
typedef const LiveBlock* const Lookup;

static uint32_t hash(const LiveBlock* const& aB)
static mozilla::HashNumber hash(const LiveBlock* const& aB)
{
return gOptions->IsDarkMatterMode()
? mozilla::HashGeneric(aB->ReqSize(),
Expand Down Expand Up @@ -1041,8 +1042,8 @@ class AggregatedLiveBlockHashPolicy

// A table of live blocks where the lookup key is everything but the block
// address. For aggregating similar live blocks at output time.
typedef js::HashMap<const LiveBlock*, size_t, AggregatedLiveBlockHashPolicy,
InfallibleAllocPolicy>
typedef mozilla::HashMap<const LiveBlock*, size_t,
AggregatedLiveBlockHashPolicy, InfallibleAllocPolicy>
AggregatedLiveBlockTable;

// A freed heap block.
Expand Down Expand Up @@ -1088,7 +1089,7 @@ class DeadBlock

typedef DeadBlock Lookup;

static uint32_t hash(const DeadBlock& aB)
static mozilla::HashNumber hash(const DeadBlock& aB)
{
return mozilla::HashGeneric(aB.ReqSize(),
aB.SlopSize(),
Expand All @@ -1105,7 +1106,7 @@ class DeadBlock

// For each unique DeadBlock value we store a count of how many actual dead
// blocks have that value.
typedef js::HashMap<DeadBlock, size_t, DeadBlock, InfallibleAllocPolicy>
typedef mozilla::HashMap<DeadBlock, size_t, DeadBlock, InfallibleAllocPolicy>
DeadBlockTable;
static DeadBlockTable* gDeadBlockTable = nullptr;

Expand Down

0 comments on commit 6998f46

Please sign in to comment.