Bug 1385953 - Remove MemProfiler; r=jandem
authorEhsan Akhgari <ehsan@mozilla.com>
Wed, 09 Aug 2017 09:49:12 -0400
changeset 423450 b7bd19d28e16ca5e4d8fe803782b4322a2db8b4d
parent 423449 6b2edbf5944a1afbb8670920eae565e5543a735e
child 423451 13521db456ac837fc298b6827b2038860133039c
push id7761
push userjlund@mozilla.com
push dateFri, 15 Sep 2017 00:19:52 +0000
treeherdermozilla-beta@c38455951db4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1385953
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1385953 - Remove MemProfiler; r=jandem This feature isn't currently used or being planned to be used in the near future and has some overhead that makes it hard to justify to keep around, so it's better to remove it and revive it from VCS history if we need it later.
browser/installer/package-manifest.in
js/src/gc/GCRuntime.h
js/src/gc/Heap.h
js/src/gc/Marking.cpp
js/src/gc/MemoryProfiler.cpp
js/src/gc/Nursery.cpp
js/src/jit/MacroAssembler.cpp
js/src/jsfriendapi.h
js/src/jsgc.cpp
js/src/moz.build
js/src/vm/ArrayBufferObject.cpp
mobile/android/installer/package-manifest.in
toolkit/toolkit.mozbuild
tools/memory-profiler/CompactTraceTable.h
tools/memory-profiler/GCHeapProfilerImpl.cpp
tools/memory-profiler/GCHeapProfilerImpl.h
tools/memory-profiler/MemoryProfiler.cpp
tools/memory-profiler/MemoryProfiler.h
tools/memory-profiler/NativeProfilerImpl.cpp
tools/memory-profiler/NativeProfilerImpl.h
tools/memory-profiler/UncensoredAllocator.cpp
tools/memory-profiler/UncensoredAllocator.h
tools/memory-profiler/moz.build
tools/memory-profiler/nsIMemoryProfiler.idl
tools/memory-profiler/nsMemoryProfilerFactory.cpp
tools/moz.build
--- a/browser/installer/package-manifest.in
+++ b/browser/installer/package-manifest.in
@@ -256,19 +256,16 @@
 @RESPATH@/browser/components/jsinspector.xpt
 @RESPATH@/components/layout_base.xpt
 #ifdef NS_PRINTING
 @RESPATH@/components/layout_printing.xpt
 #endif
 @RESPATH@/components/layout_xul_tree.xpt
 @RESPATH@/components/layout_xul.xpt
 @RESPATH@/components/locale.xpt
-#ifdef MOZ_GECKO_PROFILER
-@RESPATH@/components/memory_profiler.xpt
-#endif
 @RESPATH@/browser/components/migration.xpt
 @RESPATH@/components/mimetype.xpt
 @RESPATH@/components/mozfind.xpt
 #ifdef ENABLE_INTL_API
 @RESPATH@/components/mozintl.xpt
 #endif
 @RESPATH@/components/necko_about.xpt
 @RESPATH@/components/necko_cache.xpt
--- a/js/src/gc/GCRuntime.h
+++ b/js/src/gc/GCRuntime.h
@@ -1118,18 +1118,16 @@ class GCRuntime
 
     /* Track heap usage for this runtime. */
     HeapUsage usage;
 
     /* GC scheduling state and parameters. */
     GCSchedulingTunables tunables;
     GCSchedulingState schedulingState;
 
-    MemProfiler mMemProfiler;
-
     // State used for managing atom mark bitmaps in each zone. Protected by the
     // exclusive access lock.
     AtomMarkingRuntime atomMarking;
 
   private:
     // When empty, chunks reside in the emptyChunks pool and are re-used as
     // needed or eventually expired if not re-used. The emptyChunks pool gets
     // refilled from the background allocation task heuristically so that empty
--- a/js/src/gc/Heap.h
+++ b/js/src/gc/Heap.h
@@ -455,17 +455,16 @@ class FreeSpan
             const FreeSpan* next = nextSpan(arena);
             first = next->first;
             last = next->last;
         } else {
             return nullptr; // The span is empty.
         }
         checkSpan(arena);
         JS_EXTRA_POISON(reinterpret_cast<void*>(thing), JS_ALLOCATED_TENURED_PATTERN, thingSize);
-        MemProfiler::SampleTenured(reinterpret_cast<void*>(thing), thingSize);
         return reinterpret_cast<TenuredCell*>(thing);
     }
 
     inline void checkSpan(const Arena* arena) const;
     inline void checkRange(uintptr_t first, uintptr_t last, const Arena* arena) const;
 };
 
 /*
--- a/js/src/gc/Marking.cpp
+++ b/js/src/gc/Marking.cpp
@@ -2843,17 +2843,16 @@ js::TenuringTracer::moveToTenured(JSObje
     JSObject* dst = reinterpret_cast<JSObject*>(t);
     tenuredSize += moveObjectToTenured(dst, src, dstKind);
 
     RelocationOverlay* overlay = RelocationOverlay::fromCell(src);
     overlay->forwardTo(dst);
     insertIntoFixupList(overlay);
 
     TracePromoteToTenured(src, dst);
-    MemProfiler::MoveNurseryToTenured(src, dst);
     return dst;
 }
 
 void
 js::Nursery::collectToFixedPoint(TenuringTracer& mover, TenureCountCache& tenureCounts)
 {
     for (RelocationOverlay* p = mover.head; p; p = p->next()) {
         JSObject* obj = static_cast<JSObject*>(p->forwardingAddress());
deleted file mode 100644
--- a/js/src/gc/MemoryProfiler.cpp
+++ /dev/null
@@ -1,49 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
- * vim: set ts=8 sts=4 et sw=4 tw=99:
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "jscntxt.h"
-#include "jsfriendapi.h"
-
-#include "vm/Runtime.h"
-
-using js::gc::Cell;
-
-mozilla::Atomic<uint32_t, mozilla::Relaxed> MemProfiler::sActiveProfilerCount;
-NativeProfiler* MemProfiler::sNativeProfiler;
-
-GCHeapProfiler*
-MemProfiler::GetGCHeapProfiler(void* addr)
-{
-    JSRuntime* runtime = reinterpret_cast<Cell*>(addr)->runtimeFromAnyThread();
-    return runtime->gc.mMemProfiler.mGCHeapProfiler;
-}
-
-GCHeapProfiler*
-MemProfiler::GetGCHeapProfiler(JSRuntime* runtime)
-{
-    return runtime->gc.mMemProfiler.mGCHeapProfiler;
-}
-
-JS_FRIEND_API(MemProfiler*)
-MemProfiler::GetMemProfiler(JSContext* context)
-{
-    return &context->runtime()->gc.mMemProfiler;
-}
-
-JS_FRIEND_API(void)
-MemProfiler::start(GCHeapProfiler* aGCHeapProfiler)
-{
-    ReleaseAllJITCode(mRuntime->defaultFreeOp());
-    mGCHeapProfiler = aGCHeapProfiler;
-    sActiveProfilerCount++;
-}
-
-JS_FRIEND_API(void)
-MemProfiler::stop()
-{
-    sActiveProfilerCount--;
-    mGCHeapProfiler = nullptr;
-}
--- a/js/src/gc/Nursery.cpp
+++ b/js/src/gc/Nursery.cpp
@@ -308,17 +308,16 @@ js::Nursery::allocate(size_t size)
         if (lastCanary_) {
             MOZ_ASSERT(!lastCanary_->next);
             lastCanary_->next = canary;
         }
         lastCanary_ = canary;
     }
 #endif
 
-    MemProfiler::SampleNursery(reinterpret_cast<void*>(thing), size);
     return thing;
 }
 
 void*
 js::Nursery::allocateBuffer(Zone* zone, size_t nbytes)
 {
     MOZ_ASSERT(nbytes > 0);
 
@@ -882,17 +881,16 @@ js::Nursery::sweep()
         for (unsigned i = 0; i < numChunks(); ++i)
             chunk(i).poisonAndInit(runtime(), JS_SWEPT_NURSERY_PATTERN);
 #endif
         setCurrentChunk(0);
     }
 
     /* Set current start position for isEmpty checks. */
     setStartPosition();
-    MemProfiler::SweepNursery(runtime());
 }
 
 size_t
 js::Nursery::spaceToEnd() const
 {
     unsigned lastChunk = numChunks() - 1;
 
     MOZ_ASSERT(lastChunk >= currentStartChunk_);
--- a/js/src/jit/MacroAssembler.cpp
+++ b/js/src/jit/MacroAssembler.cpp
@@ -730,19 +730,18 @@ MacroAssembler::checkUnboxedArrayCapacit
     bind(&done);
 }
 
 // Inlined version of gc::CheckAllocatorState that checks the bare essentials
 // and bails for anything that cannot be handled with our jit allocators.
 void
 MacroAssembler::checkAllocatorState(Label* fail)
 {
-    // Don't execute the inline path if we are tracing allocations,
-    // or when the memory profiler is enabled.
-    if (js::gc::TraceEnabled() || MemProfiler::enabled())
+    // Don't execute the inline path if we are tracing allocations.
+    if (js::gc::TraceEnabled())
         jump(fail);
 
 #ifdef JS_GC_ZEAL
     // Don't execute the inline path if gc zeal or tracing are active.
     branch32(Assembler::NotEqual,
              AbsoluteAddress(GetJitContext()->runtime->addressOfGCZealModeBits()), Imm32(0),
              fail);
 #endif
--- a/js/src/jsfriendapi.h
+++ b/js/src/jsfriendapi.h
@@ -3053,167 +3053,9 @@ SetCooperativeYieldCallback(JSContext* c
 
 // Returns true if the system zone is available (i.e., if no cooperative contexts
 // are using it now).
 extern JS_FRIEND_API(bool)
 SystemZoneAvailable(JSContext* cx);
 
 } /* namespace js */
 
-class NativeProfiler
-{
-  public:
-    virtual ~NativeProfiler() {};
-    virtual void sampleNative(void* addr, uint32_t size) = 0;
-    virtual void removeNative(void* addr) = 0;
-    virtual void reset() = 0;
-};
-
-class GCHeapProfiler
-{
-  public:
-    virtual ~GCHeapProfiler() {};
-    virtual void sampleTenured(void* addr, uint32_t size) = 0;
-    virtual void sampleNursery(void* addr, uint32_t size) = 0;
-    virtual void markTenuredStart() = 0;
-    virtual void markTenured(void* addr) = 0;
-    virtual void sweepTenured() = 0;
-    virtual void sweepNursery() = 0;
-    virtual void moveNurseryToTenured(void* addrOld, void* addrNew) = 0;
-    virtual void reset() = 0;
-};
-
-class MemProfiler
-{
-    static mozilla::Atomic<uint32_t, mozilla::Relaxed> sActiveProfilerCount;
-    static JS_FRIEND_DATA(NativeProfiler*) sNativeProfiler;
-
-    static GCHeapProfiler* GetGCHeapProfiler(void* addr);
-    static GCHeapProfiler* GetGCHeapProfiler(JSRuntime* runtime);
-
-    static NativeProfiler* GetNativeProfiler() {
-        return sNativeProfiler;
-    }
-
-    GCHeapProfiler* mGCHeapProfiler;
-    JSRuntime* mRuntime;
-
-  public:
-    explicit MemProfiler(JSRuntime* aRuntime) : mGCHeapProfiler(nullptr), mRuntime(aRuntime) {}
-
-    JS_FRIEND_API(void) start(GCHeapProfiler* aGCHeapProfiler);
-    JS_FRIEND_API(void) stop();
-
-    GCHeapProfiler* getGCHeapProfiler() const {
-        return mGCHeapProfiler;
-    }
-
-    static MOZ_ALWAYS_INLINE bool enabled() {
-        return sActiveProfilerCount > 0;
-    }
-
-    static JS_FRIEND_API(MemProfiler*) GetMemProfiler(JSContext* context);
-
-    static void SetNativeProfiler(NativeProfiler* aProfiler) {
-        sNativeProfiler = aProfiler;
-    }
-
-    static MOZ_ALWAYS_INLINE void SampleNative(void* addr, uint32_t size) {
-        JS::AutoSuppressGCAnalysis nogc;
-
-        if (MOZ_LIKELY(!enabled()))
-            return;
-
-        NativeProfiler* profiler = GetNativeProfiler();
-        if (profiler)
-            profiler->sampleNative(addr, size);
-    }
-
-    static MOZ_ALWAYS_INLINE void SampleTenured(void* addr, uint32_t size) {
-        JS::AutoSuppressGCAnalysis nogc;
-
-        if (MOZ_LIKELY(!enabled()))
-            return;
-
-        GCHeapProfiler* profiler = GetGCHeapProfiler(addr);
-        if (profiler)
-            profiler->sampleTenured(addr, size);
-    }
-
-    static MOZ_ALWAYS_INLINE void SampleNursery(void* addr, uint32_t size) {
-        JS::AutoSuppressGCAnalysis nogc;
-
-        if (MOZ_LIKELY(!enabled()))
-            return;
-
-        GCHeapProfiler* profiler = GetGCHeapProfiler(addr);
-        if (profiler)
-            profiler->sampleNursery(addr, size);
-    }
-
-    static MOZ_ALWAYS_INLINE void RemoveNative(void* addr) {
-        JS::AutoSuppressGCAnalysis nogc;
-
-        if (MOZ_LIKELY(!enabled()))
-            return;
-
-        NativeProfiler* profiler = GetNativeProfiler();
-        if (profiler)
-            profiler->removeNative(addr);
-    }
-
-    static MOZ_ALWAYS_INLINE void MarkTenuredStart(JSRuntime* runtime) {
-        JS::AutoSuppressGCAnalysis nogc;
-
-        if (MOZ_LIKELY(!enabled()))
-            return;
-
-        GCHeapProfiler* profiler = GetGCHeapProfiler(runtime);
-        if (profiler)
-            profiler->markTenuredStart();
-    }
-
-    static MOZ_ALWAYS_INLINE void MarkTenured(void* addr) {
-        JS::AutoSuppressGCAnalysis nogc;
-
-        if (MOZ_LIKELY(!enabled()))
-            return;
-
-        GCHeapProfiler* profiler = GetGCHeapProfiler(addr);
-        if (profiler)
-            profiler->markTenured(addr);
-    }
-
-    static MOZ_ALWAYS_INLINE void SweepTenured(JSRuntime* runtime) {
-        JS::AutoSuppressGCAnalysis nogc;
-
-        if (MOZ_LIKELY(!enabled()))
-            return;
-
-        GCHeapProfiler* profiler = GetGCHeapProfiler(runtime);
-        if (profiler)
-            profiler->sweepTenured();
-    }
-
-    static MOZ_ALWAYS_INLINE void SweepNursery(JSRuntime* runtime) {
-        JS::AutoSuppressGCAnalysis nogc;
-
-        if (MOZ_LIKELY(!enabled()))
-            return;
-
-        GCHeapProfiler* profiler = GetGCHeapProfiler(runtime);
-        if (profiler)
-            profiler->sweepNursery();
-    }
-
-    static MOZ_ALWAYS_INLINE void MoveNurseryToTenured(void* addrOld, void* addrNew) {
-        JS::AutoSuppressGCAnalysis nogc;
-
-        if (MOZ_LIKELY(!enabled()))
-            return;
-
-        GCHeapProfiler* profiler = GetGCHeapProfiler(addrOld);
-        if (profiler)
-            profiler->moveNurseryToTenured(addrOld, addrNew);
-    }
-};
-
 #endif /* jsfriendapi_h */
--- a/js/src/jsgc.cpp
+++ b/js/src/jsgc.cpp
@@ -452,24 +452,16 @@ Arena::finalize(FreeOp* fop, AllocKind t
     uint_fast16_t firstThing = firstThingOffset(thingKind);
     uint_fast16_t firstThingOrSuccessorOfLastMarkedThing = firstThing;
     uint_fast16_t lastThing = ArenaSize - thingSize;
 
     FreeSpan newListHead;
     FreeSpan* newListTail = &newListHead;
     size_t nmarked = 0;
 
-    if (MOZ_UNLIKELY(MemProfiler::enabled())) {
-        for (ArenaCellIterUnderFinalize i(this); !i.done(); i.next()) {
-            T* t = i.get<T>();
-            if (t->asTenured().isMarkedAny())
-                MemProfiler::MarkTenured(reinterpret_cast<void*>(t));
-        }
-    }
-
     for (ArenaCellIterUnderFinalize i(this); !i.done(); i.next()) {
         T* t = i.get<T>();
         if (t->asTenured().isMarkedAny()) {
             uint_fast16_t thing = uintptr_t(t) & ArenaMask;
             if (thing != firstThingOrSuccessorOfLastMarkedThing) {
                 // We just finished passing over one or more free things,
                 // so record a new FreeSpan.
                 newListTail->initBounds(firstThingOrSuccessorOfLastMarkedThing,
@@ -827,17 +819,16 @@ GCRuntime::releaseArena(Arena* arena, co
 GCRuntime::GCRuntime(JSRuntime* rt) :
     rt(rt),
     systemZone(nullptr),
     systemZoneGroup(nullptr),
     atomsZone(nullptr),
     stats_(rt),
     marker(rt),
     usage(nullptr),
-    mMemProfiler(rt),
     nextCellUniqueId_(LargestTaggedNullCellPointer + 1), // Ensure disjoint from null tagged pointers.
     numArenasFreeCommitted(0),
     verifyPreData(nullptr),
     chunkAllocationSinceLastGC(false),
     lastGCTime(PRMJ_Now()),
     mode(JSGC_MODE_INCREMENTAL),
     numActiveZoneIters(0),
     cleanUpEverything(false),
@@ -3979,17 +3970,16 @@ GCRuntime::beginMarkPhase(JS::gcreason::
      * Ensure that after the start of a collection we don't allocate into any
      * existing arenas, as this can cause unreachable things to be marked.
      */
     if (isIncremental) {
         for (GCZonesIter zone(rt); !zone.done(); zone.next())
             zone->arenas.prepareForIncrementalGC();
     }
 
-    MemProfiler::MarkTenuredStart(rt);
     marker.start();
     GCMarker* gcmarker = &marker;
 
     {
         gcstats::AutoPhase ap1(stats(), gcstats::PhaseKind::PREPARE);
         AutoLockHelperThreadState helperLock;
 
         /*
@@ -6256,17 +6246,16 @@ GCRuntime::endCompactPhase(JS::gcreason:
 
 void
 GCRuntime::finishCollection(JS::gcreason::Reason reason)
 {
     assertBackgroundSweepingFinished();
     MOZ_ASSERT(marker.isDrained());
     marker.stop();
     clearBufferedGrayRoots();
-    MemProfiler::SweepTenured(rt);
 
     uint64_t currentTime = PRMJ_Now();
     schedulingState.updateHighFrequencyMode(lastGCTime, currentTime, tunables);
 
     for (ZonesIter zone(rt, WithAtoms); !zone.done(); zone.next()) {
         if (zone->isCollecting()) {
             zone->changeGCState(Zone::Finished, Zone::NoGC);
             zone->notifyObservingDebuggers();
--- a/js/src/moz.build
+++ b/js/src/moz.build
@@ -176,17 +176,16 @@ UNIFIED_SOURCES += [
     'frontend/TokenStream.cpp',
     'gc/Allocator.cpp',
     'gc/AtomMarking.cpp',
     'gc/Barrier.cpp',
     'gc/GCTrace.cpp',
     'gc/Iteration.cpp',
     'gc/Marking.cpp',
     'gc/Memory.cpp',
-    'gc/MemoryProfiler.cpp',
     'gc/Nursery.cpp',
     'gc/RootMarking.cpp',
     'gc/Statistics.cpp',
     'gc/Tracer.cpp',
     'gc/Verifier.cpp',
     'gc/Zone.cpp',
     'gc/ZoneGroup.cpp',
     'irregexp/NativeRegExpMacroAssembler.cpp',
--- a/js/src/vm/ArrayBufferObject.cpp
+++ b/js/src/vm/ArrayBufferObject.cpp
@@ -571,17 +571,16 @@ class js::WasmArrayRawBuffer
         if (delta && mprotect(dataEnd, delta, PROT_READ | PROT_WRITE))
             return false;
 # endif  // !XP_WIN
 
 #  if defined(MOZ_VALGRIND) && defined(VALGRIND_DISABLE_ADDR_ERROR_REPORTING_IN_RANGE)
         VALGRIND_ENABLE_ADDR_ERROR_REPORTING_IN_RANGE((unsigned char*)dataEnd, delta);
 #  endif
 
-        MemProfiler::SampleNative(dataEnd, delta);
         return true;
     }
 
 #ifndef WASM_HUGE_MEMORY
     bool extendMappedSize(uint32_t maxSize) {
         size_t newMappedSize = wasm::ComputeMappedSize(maxSize);
         MOZ_ASSERT(mappedSize_ <= newMappedSize);
         if (mappedSize_ == newMappedSize)
@@ -656,17 +655,16 @@ WasmArrayRawBuffer::Allocate(uint32_t nu
         return nullptr;
 
     // Note we will waste a page on zero-sized memories here
     if (mprotect(data, numBytesWithHeader, PROT_READ | PROT_WRITE)) {
         munmap(data, mappedSizeWithHeader);
         return nullptr;
     }
 # endif  // !XP_WIN
-    MemProfiler::SampleNative(data, numBytesWithHeader);
 
 #  if defined(MOZ_VALGRIND) && defined(VALGRIND_DISABLE_ADDR_ERROR_REPORTING_IN_RANGE)
     VALGRIND_DISABLE_ADDR_ERROR_REPORTING_IN_RANGE((unsigned char*)data + numBytesWithHeader,
                                                    mappedSizeWithHeader - numBytesWithHeader);
 #  endif
 
     uint8_t* base = reinterpret_cast<uint8_t*>(data) + gc::SystemPageSize();
     uint8_t* header = base - sizeof(WasmArrayRawBuffer);
@@ -678,17 +676,16 @@ WasmArrayRawBuffer::Allocate(uint32_t nu
 /* static */ void
 WasmArrayRawBuffer::Release(void* mem)
 {
     WasmArrayRawBuffer* header = (WasmArrayRawBuffer*)((uint8_t*)mem - sizeof(WasmArrayRawBuffer));
     uint8_t* base = header->basePointer();
     MOZ_RELEASE_ASSERT(header->mappedSize() <= SIZE_MAX - gc::SystemPageSize());
     size_t mappedSizeWithHeader = header->mappedSize() + gc::SystemPageSize();
 
-    MemProfiler::RemoveNative(base);
 # ifdef XP_WIN
     VirtualFree(base, 0, MEM_RELEASE);
 # else  // XP_WIN
     munmap(base, mappedSizeWithHeader);
 # endif  // !XP_WIN
 
 #  if defined(MOZ_VALGRIND) && defined(VALGRIND_ENABLE_ADDR_ERROR_REPORTING_IN_RANGE)
     VALGRIND_ENABLE_ADDR_ERROR_REPORTING_IN_RANGE(base, mappedSizeWithHeader);
@@ -828,17 +825,16 @@ ArrayBufferObject::prepareForAsmJS(JSCon
     buffer->setIsPreparedForAsmJS();
     return true;
 }
 
 ArrayBufferObject::BufferContents
 ArrayBufferObject::createMappedContents(int fd, size_t offset, size_t length)
 {
     void* data = AllocateMappedContent(fd, offset, length, ARRAY_BUFFER_ALIGNMENT);
-    MemProfiler::SampleNative(data, length);
     return BufferContents::create<MAPPED>(data);
 }
 
 uint8_t*
 ArrayBufferObject::inlineDataPointer() const
 {
     return static_cast<uint8_t*>(fixedData(JSCLASS_RESERVED_SLOTS(&class_)));
 }
@@ -860,17 +856,16 @@ ArrayBufferObject::releaseData(FreeOp* f
 {
     MOZ_ASSERT(ownsData());
 
     switch (bufferKind()) {
       case PLAIN:
         fop->free_(dataPointer());
         break;
       case MAPPED:
-        MemProfiler::RemoveNative(dataPointer());
         DeallocateMappedContent(dataPointer(), byteLength());
         break;
       case WASM:
         WasmArrayRawBuffer::Release(dataPointer());
         break;
       case KIND_MASK:
         MOZ_CRASH("bad bufferKind()");
     }
@@ -1812,17 +1807,16 @@ JS_PUBLIC_API(void*)
 JS_CreateMappedArrayBufferContents(int fd, size_t offset, size_t length)
 {
     return ArrayBufferObject::createMappedContents(fd, offset, length).data();
 }
 
 JS_PUBLIC_API(void)
 JS_ReleaseMappedArrayBufferContents(void* contents, size_t length)
 {
-    MemProfiler::RemoveNative(contents);
     DeallocateMappedContent(contents, length);
 }
 
 JS_FRIEND_API(bool)
 JS_IsMappedArrayBufferObject(JSObject* obj)
 {
     obj = CheckedUnwrap(obj);
     if (!obj)
--- a/mobile/android/installer/package-manifest.in
+++ b/mobile/android/installer/package-manifest.in
@@ -167,19 +167,16 @@
 @BINPATH@/components/jsinspector.xpt
 @BINPATH@/components/layout_base.xpt
 #ifdef NS_PRINTING
 @BINPATH@/components/layout_printing.xpt
 #endif
 @BINPATH@/components/layout_xul_tree.xpt
 @BINPATH@/components/layout_xul.xpt
 @BINPATH@/components/locale.xpt
-#ifdef MOZ_GECKO_PROFILER
-@BINPATH@/components/memory_profiler.xpt
-#endif
 @BINPATH@/components/mimetype.xpt
 @BINPATH@/components/mozfind.xpt
 #ifdef ENABLE_INTL_API
 @BINPATH@/components/mozintl.xpt
 #endif
 @BINPATH@/components/necko_about.xpt
 @BINPATH@/components/necko_cache.xpt
 @BINPATH@/components/necko_cache2.xpt
--- a/toolkit/toolkit.mozbuild
+++ b/toolkit/toolkit.mozbuild
@@ -103,17 +103,16 @@ else:
 # This must precede xpfe.
 if CONFIG['MOZ_JPROF']:
     DIRS += ['/tools/jprof']
 
 DIRS += [
     '/tools/code-coverage',
     '/tools/power',
     '/tools/profiler',
-    '/tools/memory-profiler',
     '/xpfe/components',
 ]
 
 if CONFIG['MOZ_ENABLE_XREMOTE']:
     DIRS += ['/widget/xremoteclient']
 
 if CONFIG['MOZ_SPELLCHECK']:
     DIRS += ['/extensions/spellcheck']
deleted file mode 100644
--- a/tools/memory-profiler/CompactTraceTable.h
+++ /dev/null
@@ -1,116 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef memory_profiler_CompactTraceTable_h
-#define memory_profiler_CompactTraceTable_h
-
-#include "mozilla/HashFunctions.h"
-
-#include "nsDataHashtable.h"
-#include "nsTArray.h"
-
-namespace mozilla {
-
-struct TrieNode final
-{
-  uint32_t parentIdx;
-  uint32_t nameIdx;
-  bool operator==(const TrieNode t) const
-  {
-    return parentIdx == t.parentIdx && nameIdx == t.nameIdx;
-  }
-  uint32_t Hash() const
-  {
-    return HashGeneric(parentIdx, nameIdx);
-  }
-};
-
-// This class maps a Node of type T to its parent's index in the
-// map. When serializing, the map is traversed and put into an ordered
-// array of Nodes.
-template<typename KeyClass, typename T>
-class NodeIndexMap final
-{
-public:
-  uint32_t Insert(const T& e)
-  {
-    uint32_t index = mMap.Count();
-    if (!mMap.Get(e, &index)) {
-      mMap.Put(e, index);
-    }
-    return index;
-  }
-
-  nsTArray<T> Serialize() const
-  {
-    nsTArray<T> v;
-    v.SetLength(mMap.Count());
-    for (auto iter = mMap.ConstIter(); !iter.Done(); iter.Next()) {
-      v[iter.Data()] = iter.Key();
-    }
-    return v;
-  }
-
-  uint32_t Size() const
-  {
-    return mMap.Count();
-  }
-
-  void Clear()
-  {
-    mMap.Clear();
-  }
-private:
-  nsDataHashtable<KeyClass, uint32_t> mMap;
-};
-
-// Backtraces are stored in a trie to save spaces.
-// Function names are stored in an unique table and TrieNodes contain indexes
-// into that table.
-// The trie is implemented with a hash table; children are stored in
-// traces[TrieNode{parent node index, branch/function name index}].
-class CompactTraceTable final
-{
-public:
-  CompactTraceTable()
-  {
-    mNames.Insert(nsAutoCString("(unknown)"));
-    mTraces.Insert(TrieNode{0, 0});
-  }
-
-  nsTArray<nsCString> GetNames() const
-  {
-    return mNames.Serialize();
-  }
-
-  nsTArray<TrieNode> GetTraces() const
-  {
-    return mTraces.Serialize();
-  }
-
-  // Returns an ID to a stacktrace.
-  uint32_t Insert(const nsTArray<nsCString>& aRawStacktrace)
-  {
-    uint32_t parent = 0;
-    for (auto& frame: aRawStacktrace) {
-      parent = mTraces.Insert(TrieNode{parent, mNames.Insert(frame)});
-    }
-    return parent;
-  }
-
-  void Reset()
-  {
-    mNames.Clear();
-    mTraces.Clear();
-  }
-private:
-  NodeIndexMap<nsCStringHashKey, nsCString> mNames;
-  NodeIndexMap<nsGenericHashKey<TrieNode>, TrieNode> mTraces;
-};
-
-} // namespace mozilla
-
-#endif // memory_profiler_CompactTraceTable_h
deleted file mode 100644
--- a/tools/memory-profiler/GCHeapProfilerImpl.cpp
+++ /dev/null
@@ -1,168 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "GCHeapProfilerImpl.h"
-
-#include "UncensoredAllocator.h"
-
-namespace mozilla {
-
-GCHeapProfilerImpl::GCHeapProfilerImpl()
-{
-  mLock = PR_NewLock();
-  mMarking = false;
-}
-
-GCHeapProfilerImpl::~GCHeapProfilerImpl()
-{
-  if (mLock) {
-    PR_DestroyLock(mLock);
-  }
-}
-
-nsTArray<nsCString>
-GCHeapProfilerImpl::GetNames() const
-{
-  return mTraceTable.GetNames();
-}
-
-nsTArray<TrieNode>
-GCHeapProfilerImpl::GetTraces() const
-{
-  return mTraceTable.GetTraces();
-}
-
-const nsTArray<AllocEvent>&
-GCHeapProfilerImpl::GetEvents() const
-{
-  return mAllocEvents;
-}
-
-void
-GCHeapProfilerImpl::reset()
-{
-  mTraceTable.Reset();
-  mAllocEvents.Clear();
-  mNurseryEntries.Clear();
-  mTenuredEntriesFG.Clear();
-  mTenuredEntriesBG.Clear();
-}
-
-void
-GCHeapProfilerImpl::sampleTenured(void* addr, uint32_t size)
-{
-  SampleInternal(addr, size, mTenuredEntriesFG);
-}
-
-void
-GCHeapProfilerImpl::sampleNursery(void* addr, uint32_t size)
-{
-  SampleInternal(addr, size, mNurseryEntries);
-}
-
-void
-GCHeapProfilerImpl::markTenuredStart()
-{
-  AutoUseUncensoredAllocator ua;
-  AutoMPLock lock(mLock);
-  if (!mMarking) {
-    mMarking = true;
-    mTenuredEntriesFG.SwapElements(mTenuredEntriesBG);
-    MOZ_ASSERT(mTenuredEntriesFG.Count() == 0);
-  }
-}
-
-void
-GCHeapProfilerImpl::markTenured(void* addr)
-{
-  AutoUseUncensoredAllocator ua;
-  AutoMPLock lock(mLock);
-  if (mMarking) {
-    AllocEntry entry;
-    if (mTenuredEntriesBG.Get(addr, &entry)) {
-      entry.mMarked = true;
-      mTenuredEntriesBG.Put(addr, entry);
-    }
-  }
-}
-
-void
-GCHeapProfilerImpl::sweepTenured()
-{
-  AutoUseUncensoredAllocator ua;
-  AutoMPLock lock(mLock);
-  if (mMarking) {
-    mMarking = false;
-    for (auto iter = mTenuredEntriesBG.Iter(); !iter.Done(); iter.Next()) {
-      if (iter.Data().mMarked) {
-        iter.Data().mMarked = false;
-        mTenuredEntriesFG.Put(iter.Key(), iter.Data());
-      } else {
-        AllocEvent& oldEvent = mAllocEvents[iter.Data().mEventIdx];
-        AllocEvent newEvent(oldEvent.mTraceIdx, -oldEvent.mSize, TimeStamp::Now());
-        mAllocEvents.AppendElement(newEvent);
-      }
-    }
-    mTenuredEntriesBG.Clear();
-  }
-}
-
-void
-GCHeapProfilerImpl::sweepNursery()
-{
-  AutoUseUncensoredAllocator ua;
-  AutoMPLock lock(mLock);
-  for (auto iter = mNurseryEntries.Iter(); !iter.Done(); iter.Next()) {
-    AllocEvent& oldEvent = mAllocEvents[iter.Data().mEventIdx];
-    AllocEvent newEvent(oldEvent.mTraceIdx, -oldEvent.mSize, TimeStamp::Now());
-    mAllocEvents.AppendElement(newEvent);
-  }
-  mNurseryEntries.Clear();
-}
-
-void
-GCHeapProfilerImpl::moveNurseryToTenured(void* addrOld, void* addrNew)
-{
-  AutoUseUncensoredAllocator ua;
-  AutoMPLock lock(mLock);
-  AllocEntry entryOld;
-  if (!mNurseryEntries.Get(addrOld, &entryOld)) {
-    return;
-  }
-
-  // Because the tenured heap is sampled, the address might already be there.
-  // If not, the address is inserted with the old event.
-  AllocEntry tenuredEntryOld;
-  if (!mTenuredEntriesFG.Get(addrNew, &tenuredEntryOld)) {
-    mTenuredEntriesFG.Put(addrNew, AllocEntry(entryOld.mEventIdx));
-  } else {
-    // If it is already inserted, the insertion above will fail and the
-    // iterator of the already-inserted element is returned.
-    // We choose to ignore the the new event by setting its size zero and point
-    // the newly allocated address to the old event.
-    // An event of size zero will be skipped when reporting.
-    mAllocEvents[entryOld.mEventIdx].mSize = 0;
-    tenuredEntryOld.mEventIdx = entryOld.mEventIdx;
-    mTenuredEntriesFG.Put(addrNew, tenuredEntryOld);
-  }
-  mNurseryEntries.Remove(addrOld);
-}
-
-void
-GCHeapProfilerImpl::SampleInternal(void* aAddr, uint32_t aSize, AllocMap& aTable)
-{
-  AutoUseUncensoredAllocator ua;
-  AutoMPLock lock(mLock);
-  size_t nSamples = AddBytesSampled(aSize);
-  if (nSamples > 0) {
-    nsTArray<nsCString> trace = GetStacktrace();
-    AllocEvent ai(mTraceTable.Insert(trace), nSamples * mSampleSize, TimeStamp::Now());
-    aTable.Put(aAddr, AllocEntry(mAllocEvents.Length()));
-    mAllocEvents.AppendElement(ai);
-  }
-}
-
-} // namespace mozilla
deleted file mode 100644
--- a/tools/memory-profiler/GCHeapProfilerImpl.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef memory_profiler_GCHeapProfilerImpl_h
-#define memory_profiler_GCHeapProfilerImpl_h
-
-#include "CompactTraceTable.h"
-#include "MemoryProfiler.h"
-
-#include "jsfriendapi.h"
-
-namespace mozilla {
-
-class GCHeapProfilerImpl final : public GCHeapProfiler
-                               , public ProfilerImpl
-{
-public:
-  GCHeapProfilerImpl();
-  ~GCHeapProfilerImpl() override;
-
-  nsTArray<nsCString> GetNames() const override;
-  nsTArray<TrieNode> GetTraces() const override;
-  const nsTArray<AllocEvent>& GetEvents() const override;
-
-  void reset() override;
-  void sampleTenured(void* addr, uint32_t size) override;
-  void sampleNursery(void* addr, uint32_t size) override;
-  void markTenuredStart() override;
-  void markTenured(void* addr) override;
-  void sweepTenured() override;
-  void sweepNursery() override;
-  void moveNurseryToTenured(void* addrOld, void* addrNew) override;
-
-private:
-  void SampleInternal(void* addr, uint32_t size, AllocMap& table);
-
-  PRLock* mLock;
-  bool mMarking;
-
-  AllocMap mNurseryEntries;
-  AllocMap mTenuredEntriesFG;
-  AllocMap mTenuredEntriesBG;
-
-  nsTArray<AllocEvent> mAllocEvents;
-  CompactTraceTable mTraceTable;
-};
-
-} // namespace mozilla
-
-#endif // memory_profiler_GCHeapProfilerImpl_h
deleted file mode 100644
--- a/tools/memory-profiler/MemoryProfiler.cpp
+++ /dev/null
@@ -1,323 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "MemoryProfiler.h"
-
-#include <cmath>
-#include <cstdlib>
-
-#include "mozilla/ClearOnShutdown.h"
-#include "mozilla/Move.h"
-#include "mozilla/TimeStamp.h"
-#include "mozilla/UniquePtr.h"
-
-#include "GCHeapProfilerImpl.h"
-#include "GeckoProfiler.h"
-#include "NativeProfilerImpl.h"
-#include "UncensoredAllocator.h"
-#include "js/TypeDecls.h"
-#include "jsfriendapi.h"
-#include "nsIDOMClassInfo.h"
-#include "nsIGlobalObject.h"
-#include "prtime.h"
-#include "xpcprivate.h"
-
-namespace mozilla {
-
-#define MEMORY_PROFILER_SAMPLE_SIZE 65536
-#define BACKTRACE_BUFFER_SIZE 16384
-
-ProfilerImpl::ProfilerImpl()
-  : mSampleSize(MEMORY_PROFILER_SAMPLE_SIZE)
-{
-  mLog1minusP = std::log(1.0 - 1.0 / mSampleSize);
-  mRemainingBytes = std::floor(std::log(1.0 - DRandom()) / mLog1minusP);
-}
-
-nsTArray<nsCString>
-ProfilerImpl::GetStacktrace()
-{
-  nsTArray<nsCString> trace;
-  auto output = MakeUnique<char[]>(BACKTRACE_BUFFER_SIZE);
-
-  profiler_get_backtrace_noalloc(output.get(), BACKTRACE_BUFFER_SIZE);
-  for (const char* p = output.get(); *p; p += strlen(p) + 1) {
-    trace.AppendElement()->Assign(p);
-  }
-
-  return trace;
-}
-
-// Generate a random number in [0, 1).
-double
-ProfilerImpl::DRandom()
-{
-  return double(((uint64_t(std::rand()) & ((1 << 26) - 1)) << 27) +
-                (uint64_t(std::rand()) & ((1 << 27) - 1)))
-    / (uint64_t(1) << 53);
-}
-
-size_t
-ProfilerImpl::AddBytesSampled(uint32_t aBytes)
-{
-  size_t nSamples = 0;
-  while (mRemainingBytes <= aBytes) {
-    mRemainingBytes += std::floor(std::log(1.0 - DRandom()) / mLog1minusP);
-    nSamples++;
-  }
-  mRemainingBytes -= aBytes;
-  return nSamples;
-}
-
-NS_IMPL_ISUPPORTS(MemoryProfiler, nsIMemoryProfiler)
-
-PRLock* MemoryProfiler::sLock;
-uint32_t MemoryProfiler::sProfileContextCount;
-StaticAutoPtr<NativeProfilerImpl> MemoryProfiler::sNativeProfiler;
-StaticAutoPtr<JSContextProfilerMap> MemoryProfiler::sJSContextProfilerMap;
-TimeStamp MemoryProfiler::sStartTime;
-
-void
-MemoryProfiler::InitOnce()
-{
-  MOZ_ASSERT(NS_IsMainThread());
-
-  static bool initialized = false;
-
-  if (!initialized) {
-    MallocHook::Initialize();
-    sLock = PR_NewLock();
-    sProfileContextCount = 0;
-    sJSContextProfilerMap = new JSContextProfilerMap();
-    ClearOnShutdown(&sJSContextProfilerMap);
-    ClearOnShutdown(&sNativeProfiler);
-    std::srand(PR_Now());
-    sStartTime = TimeStamp::ProcessCreation();
-    initialized = true;
-  }
-}
-
-NS_IMETHODIMP
-MemoryProfiler::StartProfiler()
-{
-  InitOnce();
-  AutoUseUncensoredAllocator ua;
-  AutoMPLock lock(sLock);
-  JSContext* context = XPCJSContext::Get()->Context();
-  ProfilerForJSContext profiler;
-  if (!sJSContextProfilerMap->Get(context, &profiler) ||
-      !profiler.mEnabled) {
-    if (sProfileContextCount == 0) {
-      js::EnableContextProfilingStack(context, true);
-      if (!sNativeProfiler) {
-        sNativeProfiler = new NativeProfilerImpl();
-      }
-      MemProfiler::SetNativeProfiler(sNativeProfiler);
-    }
-    GCHeapProfilerImpl* gp = new GCHeapProfilerImpl();
-    profiler.mEnabled = true;
-    profiler.mProfiler = gp;
-    sJSContextProfilerMap->Put(context, profiler);
-    MemProfiler::GetMemProfiler(context)->start(gp);
-    if (sProfileContextCount == 0) {
-      MallocHook::Enable(sNativeProfiler);
-    }
-    sProfileContextCount++;
-  }
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-MemoryProfiler::StopProfiler()
-{
-  InitOnce();
-  AutoUseUncensoredAllocator ua;
-  AutoMPLock lock(sLock);
-  JSContext* context = XPCJSContext::Get()->Context();
-  ProfilerForJSContext profiler;
-  if (sJSContextProfilerMap->Get(context, &profiler) &&
-      profiler.mEnabled) {
-    MemProfiler::GetMemProfiler(context)->stop();
-    if (--sProfileContextCount == 0) {
-      MallocHook::Disable();
-      MemProfiler::SetNativeProfiler(nullptr);
-      js::EnableContextProfilingStack(context, false);
-    }
-    profiler.mEnabled = false;
-    sJSContextProfilerMap->Put(context, profiler);
-  }
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-MemoryProfiler::ResetProfiler()
-{
-  InitOnce();
-  AutoUseUncensoredAllocator ua;
-  AutoMPLock lock(sLock);
-  JSContext* context = XPCJSContext::Get()->Context();
-  ProfilerForJSContext profiler;
-  if (!sJSContextProfilerMap->Get(context, &profiler) ||
-      !profiler.mEnabled) {
-    delete profiler.mProfiler;
-    profiler.mProfiler = nullptr;
-    sJSContextProfilerMap->Put(context, profiler);
-  }
-  if (sProfileContextCount == 0) {
-    sNativeProfiler = nullptr;
-  }
-  return NS_OK;
-}
-
-struct MergedTraces
-{
-  nsTArray<nsCString> mNames;
-  nsTArray<TrieNode> mTraces;
-  nsTArray<AllocEvent> mEvents;
-};
-
-// Merge events and corresponding traces and names.
-static MergedTraces
-MergeResults(const nsTArray<nsCString>& names0,
-             const nsTArray<TrieNode>& traces0,
-             const nsTArray<AllocEvent>& events0,
-             const nsTArray<nsCString>& names1,
-             const nsTArray<TrieNode>& traces1,
-             const nsTArray<AllocEvent>& events1)
-{
-  NodeIndexMap<nsCStringHashKey, nsCString> names;
-  NodeIndexMap<nsGenericHashKey<TrieNode>, TrieNode> traces;
-  nsTArray<AllocEvent> events;
-
-  nsTArray<size_t> names1Tonames0(names1.Length());
-  nsTArray<size_t> traces1Totraces0(traces1.Length());
-
-  // Merge names.
-  for (auto& i: names0) {
-    names.Insert(i);
-  }
-  for (auto& i: names1) {
-    names1Tonames0.AppendElement(names.Insert(i));
-  }
-
-  // Merge traces. Note that traces1[i].parentIdx < i for all i > 0.
-  for (auto& i: traces0) {
-    traces.Insert(i);
-  }
-  traces1Totraces0.AppendElement(0);
-  for (size_t i = 1; i < traces1.Length(); i++) {
-    TrieNode node = traces1[i];
-    node.parentIdx = traces1Totraces0[node.parentIdx];
-    node.nameIdx = names1Tonames0[node.nameIdx];
-    traces1Totraces0.AppendElement(traces.Insert(node));
-  }
-
-  // Merge the events according to timestamps.
-  auto p0 = events0.begin();
-  auto p1 = events1.begin();
-
-  while (p0 != events0.end() && p1 != events1.end()) {
-    if (p0->mTimestamp < p1->mTimestamp) {
-      events.AppendElement(*p0++);
-    } else {
-      events.AppendElement(*p1++);
-      events.LastElement().mTraceIdx =
-        traces1Totraces0[events.LastElement().mTraceIdx];
-    }
-  }
-
-  while (p0 != events0.end()) {
-    events.AppendElement(*p0++);
-  }
-
-  while (p1 != events1.end()) {
-    events.AppendElement(*p1++);
-    events.LastElement().mTraceIdx =
-      traces1Totraces0[events.LastElement().mTraceIdx];
-  }
-
-  return MergedTraces{names.Serialize(), traces.Serialize(), Move(events)};
-}
-
-NS_IMETHODIMP
-MemoryProfiler::GetResults(JSContext* cx, JS::MutableHandle<JS::Value> aResult)
-{
-  InitOnce();
-  AutoUseUncensoredAllocator ua;
-  AutoMPLock lock(sLock);
-  JSContext* context = XPCJSContext::Get()->Context();
-  // Getting results when the profiler is running is not allowed.
-  if (sProfileContextCount > 0) {
-    return NS_OK;
-  }
-  // Return immediately when native profiler does not exist.
-  if (!sNativeProfiler) {
-    return NS_OK;
-  }
-  // Return immediately when there's no result in current context.
-  ProfilerForJSContext profiler;
-  if (!sJSContextProfilerMap->Get(context, &profiler) ||
-      !profiler.mProfiler) {
-    return NS_OK;
-  }
-  GCHeapProfilerImpl* gp = profiler.mProfiler;
-
-  auto results = MergeResults(gp->GetNames(), gp->GetTraces(), gp->GetEvents(),
-                              sNativeProfiler->GetNames(),
-                              sNativeProfiler->GetTraces(),
-                              sNativeProfiler->GetEvents());
-  const nsTArray<nsCString>& names = results.mNames;
-  const nsTArray<TrieNode>& traces = results.mTraces;
-  const nsTArray<AllocEvent>& events = results.mEvents;
-
-  JS::RootedObject jsnames(cx, JS_NewArrayObject(cx, names.Length()));
-  JS::RootedObject jstraces(cx, JS_NewArrayObject(cx, traces.Length()));
-  JS::RootedObject jsevents(cx, JS_NewArrayObject(cx, events.Length()));
-
-  for (size_t i = 0; i < names.Length(); i++) {
-    JS::RootedString name(cx, JS_NewStringCopyZ(cx, names[i].get()));
-    JS_SetElement(cx, jsnames, i, name);
-  }
-
-  for (size_t i = 0; i < traces.Length(); i++) {
-    JS::RootedObject tn(cx, JS_NewPlainObject(cx));
-    JS::RootedValue nameIdx(cx, JS_NumberValue(traces[i].nameIdx));
-    JS::RootedValue parentIdx(cx, JS_NumberValue(traces[i].parentIdx));
-    JS_SetProperty(cx, tn, "nameIdx", nameIdx);
-    JS_SetProperty(cx, tn, "parentIdx", parentIdx);
-    JS_SetElement(cx, jstraces, i, tn);
-  }
-
-  int i = 0;
-  for (auto ent: events) {
-    if (ent.mSize == 0) {
-      continue;
-    }
-    MOZ_ASSERT(!sStartTime.IsNull());
-    double time = (ent.mTimestamp - sStartTime).ToMilliseconds();
-    JS::RootedObject tn(cx, JS_NewPlainObject(cx));
-    JS::RootedValue size(cx, JS_NumberValue(ent.mSize));
-    JS::RootedValue traceIdx(cx, JS_NumberValue(ent.mTraceIdx));
-    JS::RootedValue timestamp(cx, JS_NumberValue(time));
-    JS_SetProperty(cx, tn, "size", size);
-    JS_SetProperty(cx, tn, "traceIdx", traceIdx);
-    JS_SetProperty(cx, tn, "timestamp", timestamp);
-    JS_SetElement(cx, jsevents, i++, tn);
-  }
-  JS_SetArrayLength(cx, jsevents, i);
-
-  JS::RootedObject result(cx, JS_NewPlainObject(cx));
-  JS::RootedValue objnames(cx, ObjectOrNullValue(jsnames));
-  JS_SetProperty(cx, result, "names", objnames);
-  JS::RootedValue objtraces(cx, ObjectOrNullValue(jstraces));
-  JS_SetProperty(cx, result, "traces", objtraces);
-  JS::RootedValue objevents(cx, ObjectOrNullValue(jsevents));
-  JS_SetProperty(cx, result, "events", objevents);
-  aResult.setObject(*result);
-  return NS_OK;
-}
-
-} // namespace mozilla
deleted file mode 100644
--- a/tools/memory-profiler/MemoryProfiler.h
+++ /dev/null
@@ -1,159 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef tools_profiler_MemoryProfiler_h
-#define tools_profiler_MemoryProfiler_h
-
-#include "nsIMemoryProfiler.h"
-
-#include "mozilla/StaticPtr.h"
-#include "mozilla/TimeStamp.h"
-
-#include "CompactTraceTable.h"
-#include "nsTArray.h"
-#include "prlock.h"
-
-#define MEMORY_PROFILER_CID                                     \
-  { 0xf976eaa2, 0xcc1f, 0x47ee,                                 \
-    { 0x81, 0x29, 0xb8, 0x26, 0x2a, 0x3d, 0xb6, 0xb2 } }
-
-#define MEMORY_PROFILER_CONTRACT_ID "@mozilla.org/tools/memory-profiler;1"
-
-struct PRLock;
-
-namespace mozilla {
-
-class NativeProfilerImpl;
-class GCHeapProfilerImpl;
-
-struct ProfilerForJSContext
-{
-  ProfilerForJSContext()
-    : mProfiler(nullptr)
-    , mEnabled(false)
-  {}
-  GCHeapProfilerImpl* mProfiler;
-  bool mEnabled;
-};
-using JSContextProfilerMap =
-  nsDataHashtable<nsClearingPtrHashKey<JSContext>, ProfilerForJSContext>;
-
-class MemoryProfiler final : public nsIMemoryProfiler
-{
-public:
-  NS_DECL_ISUPPORTS
-  NS_DECL_NSIMEMORYPROFILER
-
-private:
-  static void InitOnce();
-  ~MemoryProfiler() {}
-
-  // The accesses to other static member are guarded by sLock and
-  // sProfileContextCount.
-  static PRLock* sLock;
-  static uint32_t sProfileContextCount;
-
-  static StaticAutoPtr<NativeProfilerImpl> sNativeProfiler;
-  static StaticAutoPtr<JSContextProfilerMap> sJSContextProfilerMap;
-  static TimeStamp sStartTime;
-};
-
-// Allocation events to be reported.
-struct AllocEvent {
-  TimeStamp mTimestamp;
-  // index to a stacktrace singleton.
-  uint32_t mTraceIdx;
-  // Allocation size
-  int32_t mSize;
-
-  AllocEvent(uint32_t aTraceIdx, int32_t aSize, TimeStamp aTimestamp)
-    : mTimestamp(aTimestamp)
-    , mTraceIdx(aTraceIdx)
-    , mSize(aSize)
-  {}
-};
-
-// Index to allocation events but also a mark bit to be GC-able.
-struct AllocEntry {
-  uint32_t mEventIdx : 31;
-  bool mMarked : 1;
-
-  // Default constructor for uninitialized stack value required by
-  // getter methods.
-  AllocEntry()
-    : mEventIdx(0)
-    , mMarked(false)
-  {}
-  explicit AllocEntry(int aEventIdx)
-    : mEventIdx(aEventIdx)
-    , mMarked(false)
-  {}
-};
-
-using AllocMap = nsDataHashtable<nsClearingVoidPtrHashKey, AllocEntry>;
-
-class ProfilerImpl
-{
-public:
-  static nsTArray<nsCString> GetStacktrace();
-  static double DRandom();
-
-  ProfilerImpl();
-  virtual nsTArray<nsCString> GetNames() const = 0;
-  virtual nsTArray<TrieNode> GetTraces() const = 0;
-  virtual const nsTArray<AllocEvent>& GetEvents() const = 0;
-
-protected:
-  /**
-   * The sampler generates a random variable which conforms to a geometric
-   * distribution of probability p = 1 / mSampleSize to calculate the
-   * next-to-be-sampled byte directly; It avoids rolling a dice on each byte.
-   *
-   * Let Bn denote a Bernoulli process with first success on n-th trial, the
-   * cumulative distribution function of Bn is Cn = 1 - (1 - p) ^ n.
-   * Let U denote a uniformly distributed random variable in [0, 1).
-   * A geometric random variable can be generated by Cn's reverse function:
-   * G = floor(log(1 - U) / log(1 - p)).
-   *
-   * @param aSize the number of bytes seen
-   * @return the number of events sampled
-   */
-  size_t AddBytesSampled(uint32_t aBytes);
-
-  uint32_t mSampleSize;
-
-private:
-  uint32_t mRemainingBytes;
-  double mLog1minusP;
-};
-
-/*
- * This class is used to make sure the profile data is only accessed
- * on one thread at a time. Don't use mozilla::Mutex because we don't
- * want to allocate memory.
- */
-class AutoMPLock
-{
-public:
-  explicit AutoMPLock(PRLock* aLock)
-  {
-    MOZ_ASSERT(aLock);
-    mLock = aLock;
-    PR_Lock(mLock);
-  }
-
-  ~AutoMPLock()
-  {
-    PR_Unlock(mLock);
-  }
-
-private:
-  PRLock* mLock;
-};
-
-} // namespace mozilla
-
-#endif
deleted file mode 100644
--- a/tools/memory-profiler/NativeProfilerImpl.cpp
+++ /dev/null
@@ -1,82 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "NativeProfilerImpl.h"
-
-#include "UncensoredAllocator.h"
-
-namespace mozilla {
-
-NativeProfilerImpl::NativeProfilerImpl()
-{
-  mLock = PR_NewLock();
-}
-
-NativeProfilerImpl::~NativeProfilerImpl()
-{
-  if (mLock) {
-    PR_DestroyLock(mLock);
-  }
-}
-
-nsTArray<nsCString>
-NativeProfilerImpl::GetNames() const
-{
-  return mTraceTable.GetNames();
-}
-
-nsTArray<TrieNode>
-NativeProfilerImpl::GetTraces() const
-{
-  return mTraceTable.GetTraces();
-}
-
-const nsTArray<AllocEvent>&
-NativeProfilerImpl::GetEvents() const
-{
-  return mAllocEvents;
-}
-
-void
-NativeProfilerImpl::reset()
-{
-  mTraceTable.Reset();
-  mAllocEvents.Clear();
-  mNativeEntries.Clear();
-}
-
-void
-NativeProfilerImpl::sampleNative(void* addr, uint32_t size)
-{
-  AutoUseUncensoredAllocator ua;
-  AutoMPLock lock(mLock);
-  size_t nSamples = AddBytesSampled(size);
-  if (nSamples > 0) {
-    nsTArray<nsCString> trace = GetStacktrace();
-    AllocEvent ai(mTraceTable.Insert(trace), nSamples * mSampleSize, TimeStamp::Now());
-    mNativeEntries.Put(addr, AllocEntry(mAllocEvents.Length()));
-    mAllocEvents.AppendElement(ai);
-  }
-}
-
-void
-NativeProfilerImpl::removeNative(void* addr)
-{
-  AutoUseUncensoredAllocator ua;
-  AutoMPLock lock(mLock);
-
-  AllocEntry entry;
-  if (!mNativeEntries.Get(addr, &entry)) {
-    return;
-  }
-
-  AllocEvent& oldEvent = mAllocEvents[entry.mEventIdx];
-  AllocEvent newEvent(oldEvent.mTraceIdx, -oldEvent.mSize, TimeStamp::Now());
-  mAllocEvents.AppendElement(newEvent);
-  mNativeEntries.Remove(addr);
-}
-
-} // namespace mozilla
deleted file mode 100644
--- a/tools/memory-profiler/NativeProfilerImpl.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef memory_profiler_NativeProfilerImpl_h
-#define memory_profiler_NativeProfilerImpl_h
-
-#include "CompactTraceTable.h"
-#include "MemoryProfiler.h"
-
-#include "jsfriendapi.h"
-
-struct PRLock;
-
-namespace mozilla {
-
-class NativeProfilerImpl final : public NativeProfiler
-                               , public ProfilerImpl
-{
-public:
-  NativeProfilerImpl();
-  ~NativeProfilerImpl() override;
-
-  nsTArray<nsCString> GetNames() const override;
-  nsTArray<TrieNode> GetTraces() const override;
-  const nsTArray<AllocEvent>& GetEvents() const override;
-
-  void reset() override;
-  void sampleNative(void* addr, uint32_t size) override;
-  void removeNative(void* addr) override;
-
-private:
-  PRLock* mLock;
-  AllocMap mNativeEntries;
-  nsTArray<AllocEvent> mAllocEvents;
-  CompactTraceTable mTraceTable;
-};
-
-} // namespace mozilla
-
-#endif // memory_profiler_NativeProfilerImpl_h
deleted file mode 100644
--- a/tools/memory-profiler/UncensoredAllocator.cpp
+++ /dev/null
@@ -1,121 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "UncensoredAllocator.h"
-
-#include "mozilla/Assertions.h"
-#include "mozilla/Unused.h"
-
-#include "MainThreadUtils.h"
-#include "jsfriendapi.h"
-#include "nsDebug.h"
-#include "prlock.h"
-#ifdef MOZ_REPLACE_MALLOC
-#include "replace_malloc_bridge.h"
-#endif
-
-namespace mozilla {
-
-#ifdef MOZ_REPLACE_MALLOC
-MOZ_THREAD_LOCAL(bool) MallocHook::mEnabledTLS;
-NativeProfiler* MallocHook::mNativeProfiler;
-malloc_hook_table_t MallocHook::mMallocHook;
-#endif
-
-AutoUseUncensoredAllocator::AutoUseUncensoredAllocator()
-{
-#ifdef MOZ_REPLACE_MALLOC
-  MallocHook::mEnabledTLS.set(false);
-#endif
-}
-
-AutoUseUncensoredAllocator::~AutoUseUncensoredAllocator()
-{
-#ifdef MOZ_REPLACE_MALLOC
-  MallocHook::mEnabledTLS.set(true);
-#endif
-}
-
-bool
-MallocHook::Enabled()
-{
-#ifdef MOZ_REPLACE_MALLOC
-  return mEnabledTLS.get() && mNativeProfiler;
-#else
-  return false;
-#endif
-}
-
-void*
-MallocHook::SampleNative(void* aAddr, size_t aSize)
-{
-#ifdef MOZ_REPLACE_MALLOC
-  if (MallocHook::Enabled()) {
-    mNativeProfiler->sampleNative(aAddr, aSize);
-  }
-#endif
-  return aAddr;
-}
-
-void
-MallocHook::RemoveNative(void* aAddr)
-{
-#ifdef MOZ_REPLACE_MALLOC
-  if (MallocHook::Enabled()) {
-    mNativeProfiler->removeNative(aAddr);
-  }
-#endif
-}
-
-void
-MallocHook::Initialize()
-{
-#ifdef MOZ_REPLACE_MALLOC
-  MOZ_ASSERT(NS_IsMainThread());
-  mMallocHook.free_hook = RemoveNative;
-  mMallocHook.malloc_hook = SampleNative;
-  ReplaceMallocBridge* bridge = ReplaceMallocBridge::Get(3);
-  if (bridge) {
-    mozilla::Unused << bridge->RegisterHook("memory-profiler", nullptr, nullptr);
-  }
-
-  bool success = mEnabledTLS.init();
-  if (NS_WARN_IF(!success)) {
-    return;
-  }
-#endif
-}
-
-void
-MallocHook::Enable(NativeProfiler* aNativeProfiler)
-{
-#ifdef MOZ_REPLACE_MALLOC
-  MOZ_ASSERT(NS_IsMainThread());
-  ReplaceMallocBridge* bridge = ReplaceMallocBridge::Get(3);
-  if (bridge) {
-    const malloc_table_t* alloc_funcs =
-      bridge->RegisterHook("memory-profiler", nullptr, &mMallocHook);
-    if (alloc_funcs) {
-      mNativeProfiler = aNativeProfiler;
-    }
-  }
-#endif
-}
-
-void
-MallocHook::Disable()
-{
-#ifdef MOZ_REPLACE_MALLOC
-  MOZ_ASSERT(NS_IsMainThread());
-  ReplaceMallocBridge* bridge = ReplaceMallocBridge::Get(3);
-  if (bridge) {
-    bridge->RegisterHook("memory-profiler", nullptr, nullptr);
-    mNativeProfiler = nullptr;
-  }
-#endif
-}
-
-} // namespace mozilla
deleted file mode 100644
--- a/tools/memory-profiler/UncensoredAllocator.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef memory_profiler_UncensoredAllocator_h
-#define memory_profiler_UncensoredAllocator_h
-
-#include "mozilla/Attributes.h"
-#include "mozilla/ThreadLocal.h"
-
-#ifdef MOZ_REPLACE_MALLOC
-#include "replace_malloc_bridge.h"
-#endif
-
-class NativeProfiler;
-
-namespace mozilla {
-
-class MallocHook final
-{
-public:
-  static void Initialize();
-  static void Enable(NativeProfiler* aNativeProfiler);
-  static void Disable();
-  static bool Enabled();
-private:
-  static void* SampleNative(void* aAddr, size_t aSize);
-  static void RemoveNative(void* aAddr);
-#ifdef MOZ_REPLACE_MALLOC
-  static MOZ_THREAD_LOCAL(bool) mEnabledTLS;
-  static NativeProfiler* mNativeProfiler;
-  static malloc_hook_table_t mMallocHook;
-#endif
-  friend class AutoUseUncensoredAllocator;
-};
-
-class MOZ_RAII AutoUseUncensoredAllocator final
-{
-public:
-  AutoUseUncensoredAllocator();
-  ~AutoUseUncensoredAllocator();
-};
-
-} // namespace mozilla
-
-#endif // memory_profiler_UncensoredAllocator_h
deleted file mode 100644
--- a/tools/memory-profiler/moz.build
+++ /dev/null
@@ -1,29 +0,0 @@
-# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
-# vim: set filetype=python:
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-if CONFIG['MOZ_GECKO_PROFILER']:
-    XPIDL_MODULE = 'memory_profiler'
-    XPIDL_SOURCES += [
-        'nsIMemoryProfiler.idl',
-    ]
-
-    UNIFIED_SOURCES += [
-        'GCHeapProfilerImpl.cpp',
-        'MemoryProfiler.cpp',
-        'NativeProfilerImpl.cpp',
-        'nsMemoryProfilerFactory.cpp',
-        'UncensoredAllocator.cpp',
-    ]
-
-    LOCAL_INCLUDES += [
-        '/js/xpconnect/src',
-        '/xpcom/base',
-    ]
-
-    FINAL_LIBRARY = 'xul'
-
-if CONFIG['GNU_CXX']:
-    CXXFLAGS += ['-Wno-error=shadow']
deleted file mode 100644
--- a/tools/memory-profiler/nsIMemoryProfiler.idl
+++ /dev/null
@@ -1,72 +0,0 @@
-/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "nsISupports.idl"
-
-/**
- * The memory profiler samples allocation events. An allocation event
- * includes a type (what and at where is going to be allocated), a
- * size, a timestamp and the corresponding stack trace. Free events
- * are also tracked. For managed languages, namely languages relying
- * on garbage collection, a free event is generated when an object is
- * reclaimed by the garbage collector.  These sampled events can be
- * used to approximate the full history of allocations afterwards.
- * That means we can get various memory profiles of a program in
- * different perspectives by post-processing the history in different
- * ways. The profiler is designed at the very beginning to support not
- * only JavaScript but also native codes. Naturally, not only
- * JavaScript objects but also native allocations are tracked.
- *
- * The result returned is the sampled allocation event traces in a
- * compact format. The events is sorted according to the timestamp
- * when the event happened. Each event has a trace index pointing to
- * the traces table. Each trace entry has a name index pointing to the
- * names table and a parent index pointing to the parent trace in the
- * traces table. By following the trace index one could rebuild the
- * complete backtrace of an allocation event.
- *
- *    [ Events ]
- *    +-------+-------+      +-------+
- *    | Size  | Size  |      | Size  |
- *    |-------|-------|      |-------|
- *    | Time  | Time  |......| Time  |
- *    |-------|-------|      |-------|
- *  +-- Trace | Trace |      | Trace |
- *  | +-------+-------+      +-------+
- *  |
- *  | [ Traces ]
- *  +->--------+--------+   +--------+   +--------+
- *   -| Name   | Name   |   | Name   |   | Name   |
- *  / |--------|--------|...|--------|...|--------|
- *  | | Parent | Parent |   | Parent |   | Parent |
- *  | +---|----+----^--++   +--^--|--+   +---^----+
- *  |     |         |  |       |  |          |
- *  |     +---------+  +-------+  +----------+
- *  | [ Names ]
- *  | +-----------------+-----------------+
- *  +-> Function name   | Function name   |
- *    |  & line numbers |  & line numbers |......
- *    +-----------------+-----------------+
- *
- */
-[scriptable, uuid(1e10e7a9-bc05-4878-a687-36c9ea4428b1)]
-interface nsIMemoryProfiler : nsISupports
-{
-  void startProfiler();
-  void stopProfiler();
-  void resetProfiler();
-
-  /**
-   * Get results in an object which contains three tables:
-   * {
-   *  names, // an array of function names and positions
-   *  traces, // an array of {nameIdx, parentIdx}
-   *  events, // an array of {size, timestamp, traceIdx}
-   * }
-   * Should only be called after stopProfiler.
-   */
-  [implicit_jscontext]
-  jsval getResults();
-};
deleted file mode 100644
--- a/tools/memory-profiler/nsMemoryProfilerFactory.cpp
+++ /dev/null
@@ -1,32 +0,0 @@
-/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "mozilla/ModuleUtils.h"
-#include "nsCOMPtr.h"
-#include "MemoryProfiler.h"
-
-using mozilla::MemoryProfiler;
-
-NS_GENERIC_FACTORY_CONSTRUCTOR(MemoryProfiler)
-
-NS_DEFINE_NAMED_CID(MEMORY_PROFILER_CID);
-
-static const mozilla::Module::CIDEntry kMemoryProfilerCIDs[] = {
-  { &kMEMORY_PROFILER_CID, false, nullptr, MemoryProfilerConstructor },
-  { nullptr }
-};
-
-static const mozilla::Module::ContractIDEntry kMemoryProfilerContracts[] = {
-  { MEMORY_PROFILER_CONTRACT_ID, &kMEMORY_PROFILER_CID },
-  { nullptr }
-};
-
-static const mozilla::Module kMemoryProfilerModule = {
-  mozilla::Module::kVersion,
-  kMemoryProfilerCIDs,
-  kMemoryProfilerContracts
-};
-
-NSMODULE_DEFN(nsMemoryProfilerModule) = &kMemoryProfilerModule;
--- a/tools/moz.build
+++ b/tools/moz.build
@@ -20,19 +20,16 @@ with Files("coverity/**"):
     BUG_COMPONENT = ("Core", "Rewriting and Analysis")
 
 with Files("docs/**"):
     BUG_COMPONENT = ("Core", "Build Config")
 
 with Files("lint/**"):
     BUG_COMPONENT = ("Testing", "Lint")
 
-with Files("memory-profiler/**"):
-    BUG_COMPONENT = ("Core", "Gecko Profiler")
-
 with Files("mercurial/**"):
     BUG_COMPONENT = ("Core", "Build Config")
 
 with Files("profiler/**"):
     BUG_COMPONENT = ("Core", "Gecko Profiler")
 
 with Files("quitter/**"):
     BUG_COMPONENT = ("Testing", "General")