summaryrefslogtreecommitdiffstats
path: root/memory/replace/dmd/test
diff options
context:
space:
mode:
Diffstat (limited to 'memory/replace/dmd/test')
-rw-r--r--memory/replace/dmd/test/SmokeDMD.cpp378
-rw-r--r--memory/replace/dmd/test/basic-scan-32-expected.txt25
-rw-r--r--memory/replace/dmd/test/basic-scan-64-expected.txt25
-rw-r--r--memory/replace/dmd/test/complete-empty-cumulative-expected.txt18
-rw-r--r--memory/replace/dmd/test/complete-empty-dark-matter-expected.txt29
-rw-r--r--memory/replace/dmd/test/complete-empty-live-expected.txt18
-rw-r--r--memory/replace/dmd/test/complete-full1-dark-matter-expected.txt265
-rw-r--r--memory/replace/dmd/test/complete-full1-live-expected.txt127
-rw-r--r--memory/replace/dmd/test/complete-full2-cumulative-expected.txt173
-rw-r--r--memory/replace/dmd/test/complete-full2-dark-matter-expected.txt140
-rw-r--r--memory/replace/dmd/test/complete-partial-live-expected.txt56
-rw-r--r--memory/replace/dmd/test/moz.build26
-rw-r--r--memory/replace/dmd/test/scan-test.py102
-rw-r--r--memory/replace/dmd/test/script-diff-dark-matter-expected.txt127
-rw-r--r--memory/replace/dmd/test/script-diff-dark-matter1.json51
-rw-r--r--memory/replace/dmd/test/script-diff-dark-matter2.json51
-rw-r--r--memory/replace/dmd/test/script-diff-live-expected.txt81
-rw-r--r--memory/replace/dmd/test/script-diff-live1.json51
-rw-r--r--memory/replace/dmd/test/script-diff-live2.json53
-rw-r--r--memory/replace/dmd/test/script-ignore-alloc-fns-expected.txt72
-rw-r--r--memory/replace/dmd/test/script-ignore-alloc-fns.json45
-rw-r--r--memory/replace/dmd/test/script-max-frames-1-expected.txt26
-rw-r--r--memory/replace/dmd/test/script-max-frames-3-expected.txt48
-rw-r--r--memory/replace/dmd/test/script-max-frames-8-expected.txt69
-rw-r--r--memory/replace/dmd/test/script-max-frames.json43
-rw-r--r--memory/replace/dmd/test/script-sort-by-num-blocks-expected.txt46
-rw-r--r--memory/replace/dmd/test/script-sort-by-req-expected.txt46
-rw-r--r--memory/replace/dmd/test/script-sort-by-slop-expected.txt46
-rw-r--r--memory/replace/dmd/test/script-sort-by-usable-expected.txt46
-rw-r--r--memory/replace/dmd/test/script-sort-by.json.gzbin0 -> 272 bytes
-rw-r--r--memory/replace/dmd/test/test_dmd.js224
-rw-r--r--memory/replace/dmd/test/xpcshell.ini35
32 files changed, 2542 insertions, 0 deletions
diff --git a/memory/replace/dmd/test/SmokeDMD.cpp b/memory/replace/dmd/test/SmokeDMD.cpp
new file mode 100644
index 0000000000..c72e92a543
--- /dev/null
+++ b/memory/replace/dmd/test/SmokeDMD.cpp
@@ -0,0 +1,378 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=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/. */
+
+// This program is used by the DMD xpcshell test. It is run under DMD and
+// produces some output. The xpcshell test then post-processes and checks this
+// output.
+//
+// Note that this file does not have "Test" or "test" in its name, because that
+// will cause the build system to not record breakpad symbols for it, which
+// will stop the post-processing (which includes stack fixing) from working
+// correctly.
+
+// This is required on some systems such as Fedora to allow
+// building with -O0 together with --warnings-as-errors due to
+// a check in /usr/include/features.h
+#undef _FORTIFY_SOURCE
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "mozilla/Assertions.h"
+#include "mozilla/JSONWriter.h"
+#include "mozilla/Sprintf.h"
+#include "mozilla/UniquePtr.h"
+#include "DMD.h"
+
+using mozilla::MakeUnique;
+using namespace mozilla::dmd;
+
+DMDFuncs::Singleton DMDFuncs::sSingleton;
+
+class FpWriteFunc final : public mozilla::JSONWriteFunc {
+ public:
+ explicit FpWriteFunc(const char* aFilename) {
+ mFp = fopen(aFilename, "w");
+ if (!mFp) {
+ fprintf(stderr, "SmokeDMD: can't create %s file: %s\n", aFilename,
+ strerror(errno));
+ exit(1);
+ }
+ }
+
+ ~FpWriteFunc() { fclose(mFp); }
+
+ void Write(const mozilla::Span<const char>& aStr) final {
+ for (const char c : aStr) {
+ fputc(c, mFp);
+ }
+ }
+
+ private:
+ FILE* mFp;
+};
+
+// This stops otherwise-unused variables from being optimized away.
+static void UseItOrLoseIt(void* aPtr, int aSeven) {
+ char buf[64];
+ int n = SprintfLiteral(buf, "%p\n", aPtr);
+ if (n == 20 + aSeven) {
+ fprintf(stderr, "well, that is surprising");
+ }
+}
+
+// This function checks that heap blocks that have the same stack trace but
+// different (or no) reporters get aggregated separately.
+void Foo(int aSeven) {
+ char* a[6];
+ for (int i = 0; i < aSeven - 1; i++) {
+ a[i] = (char*)malloc(128 - 16 * i);
+ UseItOrLoseIt(a[i], aSeven);
+ }
+
+ // Oddly, some versions of clang will cause identical stack traces to be
+ // generated for adjacent calls to Report(), which breaks the test. Inserting
+ // the UseItOrLoseIt() calls in between is enough to prevent this.
+
+ Report(a[2]); // reported
+
+ UseItOrLoseIt(a[2], aSeven);
+
+ for (int i = 0; i < aSeven - 5; i++) {
+ Report(a[i]); // reported
+ UseItOrLoseIt(a[i], aSeven);
+ }
+
+ UseItOrLoseIt(a[2], aSeven);
+
+ Report(a[3]); // reported
+
+ // a[4], a[5] unreported
+}
+
+void TestEmpty(const char* aTestName, const char* aMode) {
+ char filename[128];
+ SprintfLiteral(filename, "complete-%s-%s.json", aTestName, aMode);
+ auto f = MakeUnique<FpWriteFunc>(filename);
+
+ char options[128];
+ SprintfLiteral(options, "--mode=%s --stacks=full", aMode);
+ ResetEverything(options);
+
+ // Zero for everything.
+ Analyze(std::move(f));
+}
+
+void TestFull(const char* aTestName, int aNum, const char* aMode, int aSeven) {
+ char filename[128];
+ SprintfLiteral(filename, "complete-%s%d-%s.json", aTestName, aNum, aMode);
+ auto f = MakeUnique<FpWriteFunc>(filename);
+
+ // The --show-dump-stats=yes is there just to give that option some basic
+ // testing, e.g. ensure it doesn't crash. It's hard to test much beyond that.
+ char options[128];
+ SprintfLiteral(options, "--mode=%s --stacks=full --show-dump-stats=yes",
+ aMode);
+ ResetEverything(options);
+
+ // Analyze 1: 1 freed, 9 out of 10 unreported.
+ // Analyze 2: still present and unreported.
+ int i;
+ char* a = nullptr;
+ for (i = 0; i < aSeven + 3; i++) {
+ a = (char*)malloc(100);
+ UseItOrLoseIt(a, aSeven);
+ }
+ free(a);
+
+ // A no-op.
+ free(nullptr);
+
+ // Note: 16 bytes is the smallest requested size that gives consistent
+ // behaviour across all platforms with jemalloc.
+ // Analyze 1: reported.
+ // Analyze 2: thrice-reported.
+ char* a2 = (char*)malloc(16);
+ Report(a2);
+
+ // Analyze 1: reported.
+ // Analyze 2: reportedness carries over, due to ReportOnAlloc.
+ char* b = (char*)malloc(10);
+ ReportOnAlloc(b);
+
+ // ReportOnAlloc, then freed.
+ // Analyze 1: freed, irrelevant.
+ // Analyze 2: freed, irrelevant.
+ char* b2 = (char*)malloc(16);
+ ReportOnAlloc(b2);
+ free(b2);
+
+ // Analyze 1: reported 4 times.
+ // Analyze 2: freed, irrelevant.
+ char* c = (char*)calloc(10, 3);
+ Report(c);
+ for (int i = 0; i < aSeven - 4; i++) {
+ Report(c);
+ }
+
+ // Analyze 1: ignored.
+ // Analyze 2: irrelevant.
+ Report((void*)(intptr_t)i);
+
+ // jemalloc rounds this up to 8192.
+ // Analyze 1: reported.
+ // Analyze 2: freed.
+ char* e = (char*)malloc(4096);
+ e = (char*)realloc(e, 7169);
+ Report(e);
+
+ // First realloc is like malloc; second realloc is shrinking.
+ // Analyze 1: reported.
+ // Analyze 2: re-reported.
+ char* e2 = (char*)realloc(nullptr, 1024);
+ e2 = (char*)realloc(e2, 512);
+ Report(e2);
+
+ // First realloc is like malloc; second realloc creates a min-sized block.
+ // XXX: on Windows, second realloc frees the block.
+ // Analyze 1: reported.
+ // Analyze 2: freed, irrelevant.
+ char* e3 = (char*)realloc(nullptr, 1023);
+ // e3 = (char*) realloc(e3, 0);
+ MOZ_ASSERT(e3);
+ Report(e3);
+
+ // Analyze 1: freed, irrelevant.
+ // Analyze 2: freed, irrelevant.
+ char* f1 = (char*)malloc(64);
+ UseItOrLoseIt(f1, aSeven);
+ free(f1);
+
+ // Analyze 1: ignored.
+ // Analyze 2: irrelevant.
+ Report((void*)(intptr_t)0x0);
+
+ // Analyze 1: mixture of reported and unreported.
+ // Analyze 2: all unreported.
+ Foo(aSeven);
+
+ // Analyze 1: twice-reported.
+ // Analyze 2: twice-reported.
+ char* g1 = (char*)malloc(77);
+ ReportOnAlloc(g1);
+ ReportOnAlloc(g1);
+
+ // Analyze 1: mixture of reported and unreported.
+ // Analyze 2: all unreported.
+ // Nb: this Foo() call is deliberately not adjacent to the previous one. See
+ // the comment about adjacent calls in Foo() for more details.
+ Foo(aSeven);
+
+ // Analyze 1: twice-reported.
+ // Analyze 2: once-reported.
+ char* g2 = (char*)malloc(78);
+ Report(g2);
+ ReportOnAlloc(g2);
+
+ // Analyze 1: twice-reported.
+ // Analyze 2: once-reported.
+ char* g3 = (char*)malloc(79);
+ ReportOnAlloc(g3);
+ Report(g3);
+
+ // All the odd-ball ones.
+ // Analyze 1: all unreported.
+ // Analyze 2: all freed, irrelevant.
+ // XXX: no memalign on Mac
+ // void* w = memalign(64, 65); // rounds up to 128
+ // UseItOrLoseIt(w, aSeven);
+
+ // XXX: posix_memalign doesn't work on B2G
+ // void* x;
+ // posix_memalign(&y, 128, 129); // rounds up to 256
+ // UseItOrLoseIt(x, aSeven);
+
+ // XXX: valloc doesn't work on Windows.
+ // void* y = valloc(1); // rounds up to 4096
+ // UseItOrLoseIt(y, aSeven);
+
+ // XXX: C11 only
+ // void* z = aligned_alloc(64, 256);
+ // UseItOrLoseIt(z, aSeven);
+
+ if (aNum == 1) {
+ // Analyze 1.
+ Analyze(std::move(f));
+ }
+
+ ClearReports();
+
+ //---------
+
+ Report(a2);
+ Report(a2);
+ free(c);
+ free(e);
+ Report(e2);
+ free(e3);
+ // free(w);
+ // free(x);
+ // free(y);
+ // free(z);
+
+ // Do some allocations that will only show up in cumulative mode.
+ for (int i = 0; i < 100; i++) {
+ void* v = malloc(128);
+ UseItOrLoseIt(v, aSeven);
+ free(v);
+ }
+
+ if (aNum == 2) {
+ // Analyze 2.
+ Analyze(std::move(f));
+ }
+}
+
+void TestPartial(const char* aTestName, const char* aMode, int aSeven) {
+ char filename[128];
+ SprintfLiteral(filename, "complete-%s-%s.json", aTestName, aMode);
+ auto f = MakeUnique<FpWriteFunc>(filename);
+
+ char options[128];
+ SprintfLiteral(options, "--mode=%s", aMode);
+ ResetEverything(options);
+
+ int kTenThousand = aSeven + 9993;
+ char* s;
+
+ // The output of this function is deterministic but it relies on the
+ // probability and seeds given to the FastBernoulliTrial instance in
+ // ResetBernoulli(). If they change, the output will change too.
+
+ // Expected fraction with stacks: (1 - (1 - 0.003) ** 16) = 0.0469.
+ // So we expect about 0.0469 * 10000 == 469.
+ // We actually get 511.
+ for (int i = 0; i < kTenThousand; i++) {
+ s = (char*)malloc(16);
+ UseItOrLoseIt(s, aSeven);
+ }
+
+ // Expected fraction with stacks: (1 - (1 - 0.003) ** 128) = 0.3193.
+ // So we expect about 0.3193 * 10000 == 3193.
+ // We actually get 3136.
+ for (int i = 0; i < kTenThousand; i++) {
+ s = (char*)malloc(128);
+ UseItOrLoseIt(s, aSeven);
+ }
+
+ // Expected fraction with stacks: (1 - (1 - 0.003) ** 1024) = 0.9539.
+ // So we expect about 0.9539 * 10000 == 9539.
+ // We actually get 9531.
+ for (int i = 0; i < kTenThousand; i++) {
+ s = (char*)malloc(1024);
+ UseItOrLoseIt(s, aSeven);
+ }
+
+ Analyze(std::move(f));
+}
+
+void TestScan(int aSeven) {
+ auto f = MakeUnique<FpWriteFunc>("basic-scan.json");
+
+ ResetEverything("--mode=scan");
+
+ uintptr_t* p = (uintptr_t*)malloc(6 * sizeof(uintptr_t));
+ UseItOrLoseIt(p, aSeven);
+
+ // Hard-coded values checked by scan-test.py
+ p[0] = 0x123; // outside a block, small value
+ p[1] = 0x0; // null
+ p[2] = (uintptr_t)((uint8_t*)p - 1); // pointer outside a block, but nearby
+ p[3] = (uintptr_t)p; // pointer to start of a block
+ p[4] = (uintptr_t)((uint8_t*)p + 1); // pointer into a block
+ p[5] = 0x0; // trailing null
+
+ Analyze(std::move(f));
+}
+
+void RunTests() {
+ // This test relies on the compiler not doing various optimizations, such as
+ // eliding unused malloc() calls or unrolling loops with fixed iteration
+ // counts. So we compile it with -O0 (or equivalent), which probably prevents
+ // that. We also use the following variable for various loop iteration
+ // counts, just in case compilers might unroll very small loops even with
+ // -O0.
+ int seven = 7;
+
+ // Make sure that DMD is actually running; it is initialized on the first
+ // allocation.
+ int* x = (int*)malloc(100);
+ UseItOrLoseIt(x, seven);
+ MOZ_RELEASE_ASSERT(IsRunning());
+
+ // Please keep this in sync with run_test in test_dmd.js.
+
+ TestEmpty("empty", "live");
+ TestEmpty("empty", "dark-matter");
+ TestEmpty("empty", "cumulative");
+
+ TestFull("full", 1, "live", seven);
+ TestFull("full", 1, "dark-matter", seven);
+
+ TestFull("full", 2, "dark-matter", seven);
+ TestFull("full", 2, "cumulative", seven);
+
+ TestPartial("partial", "live", seven);
+
+ TestScan(seven);
+}
+
+int main() {
+ RunTests();
+
+ return 0;
+}
diff --git a/memory/replace/dmd/test/basic-scan-32-expected.txt b/memory/replace/dmd/test/basic-scan-32-expected.txt
new file mode 100644
index 0000000000..9f6f4db325
--- /dev/null
+++ b/memory/replace/dmd/test/basic-scan-32-expected.txt
@@ -0,0 +1,25 @@
+#-----------------------------------------------------------------
+# dmd.py --filter-stacks-for-testing -o basic-scan-32-actual.txt --clamp-contents basic-scan.json
+
+Invocation {
+ $DMD = '--mode=scan'
+ Mode = 'live'
+}
+
+#-----------------------------------------------------------------
+
+Live {
+ 1 block in heap block record 1 of 1
+ 32 bytes (24 requested / 8 slop)
+ 100.00% of the heap (100.00% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+#-----------------------------------------------------------------
+
+Summary {
+ Total: 32 bytes in 1 blocks
+}
+
diff --git a/memory/replace/dmd/test/basic-scan-64-expected.txt b/memory/replace/dmd/test/basic-scan-64-expected.txt
new file mode 100644
index 0000000000..59effc07b7
--- /dev/null
+++ b/memory/replace/dmd/test/basic-scan-64-expected.txt
@@ -0,0 +1,25 @@
+#-----------------------------------------------------------------
+# dmd.py --filter-stacks-for-testing -o basic-scan-64-actual.txt --clamp-contents basic-scan.json
+
+Invocation {
+ $DMD = '--mode=scan'
+ Mode = 'live'
+}
+
+#-----------------------------------------------------------------
+
+Live {
+ 1 block in heap block record 1 of 1
+ 48 bytes (48 requested / 0 slop)
+ 100.00% of the heap (100.00% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+#-----------------------------------------------------------------
+
+Summary {
+ Total: 48 bytes in 1 blocks
+}
+
diff --git a/memory/replace/dmd/test/complete-empty-cumulative-expected.txt b/memory/replace/dmd/test/complete-empty-cumulative-expected.txt
new file mode 100644
index 0000000000..2486015d0b
--- /dev/null
+++ b/memory/replace/dmd/test/complete-empty-cumulative-expected.txt
@@ -0,0 +1,18 @@
+#-----------------------------------------------------------------
+# dmd.py --filter-stacks-for-testing -o complete-empty-cumulative-actual.txt complete-empty-cumulative.json
+
+Invocation {
+ $DMD = '--mode=cumulative --stacks=full'
+ Mode = 'cumulative'
+}
+
+#-----------------------------------------------------------------
+
+# no cumulative heap blocks
+
+#-----------------------------------------------------------------
+
+Summary {
+ Total: 0 bytes in 0 blocks
+}
+
diff --git a/memory/replace/dmd/test/complete-empty-dark-matter-expected.txt b/memory/replace/dmd/test/complete-empty-dark-matter-expected.txt
new file mode 100644
index 0000000000..0020cddde3
--- /dev/null
+++ b/memory/replace/dmd/test/complete-empty-dark-matter-expected.txt
@@ -0,0 +1,29 @@
+#-----------------------------------------------------------------
+# dmd.py --filter-stacks-for-testing -o complete-empty-dark-matter-actual.txt complete-empty-dark-matter.json
+
+Invocation {
+ $DMD = '--mode=dark-matter --stacks=full'
+ Mode = 'dark-matter'
+}
+
+#-----------------------------------------------------------------
+
+# no twice-reported heap blocks
+
+#-----------------------------------------------------------------
+
+# no unreported heap blocks
+
+#-----------------------------------------------------------------
+
+# no once-reported heap blocks
+
+#-----------------------------------------------------------------
+
+Summary {
+ Total: 0 bytes (100.00%) in 0 blocks (100.00%)
+ Unreported: 0 bytes ( 0.00%) in 0 blocks ( 0.00%)
+ Once-reported: 0 bytes ( 0.00%) in 0 blocks ( 0.00%)
+ Twice-reported: 0 bytes ( 0.00%) in 0 blocks ( 0.00%)
+}
+
diff --git a/memory/replace/dmd/test/complete-empty-live-expected.txt b/memory/replace/dmd/test/complete-empty-live-expected.txt
new file mode 100644
index 0000000000..d0d1721965
--- /dev/null
+++ b/memory/replace/dmd/test/complete-empty-live-expected.txt
@@ -0,0 +1,18 @@
+#-----------------------------------------------------------------
+# dmd.py --filter-stacks-for-testing -o complete-empty-live-actual.txt complete-empty-live.json
+
+Invocation {
+ $DMD = '--mode=live --stacks=full'
+ Mode = 'live'
+}
+
+#-----------------------------------------------------------------
+
+# no live heap blocks
+
+#-----------------------------------------------------------------
+
+Summary {
+ Total: 0 bytes in 0 blocks
+}
+
diff --git a/memory/replace/dmd/test/complete-full1-dark-matter-expected.txt b/memory/replace/dmd/test/complete-full1-dark-matter-expected.txt
new file mode 100644
index 0000000000..2c7d6b6343
--- /dev/null
+++ b/memory/replace/dmd/test/complete-full1-dark-matter-expected.txt
@@ -0,0 +1,265 @@
+#-----------------------------------------------------------------
+# dmd.py --filter-stacks-for-testing -o complete-full1-dark-matter-actual.txt complete-full1-dark-matter.json
+
+Invocation {
+ $DMD = '--mode=dark-matter --stacks=full --show-dump-stats=yes'
+ Mode = 'dark-matter'
+}
+
+#-----------------------------------------------------------------
+
+Twice-reported {
+ 1 block in heap block record 1 of 4
+ 80 bytes (79 requested / 1 slop)
+ 0.66% of the heap (0.66% cumulative)
+ 29.41% of twice-reported (29.41% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+ Reported at {
+ #01: ... DMD.cpp ...
+ }
+ Reported again at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+Twice-reported {
+ 1 block in heap block record 2 of 4
+ 80 bytes (78 requested / 2 slop)
+ 0.66% of the heap (1.32% cumulative)
+ 29.41% of twice-reported (58.82% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+ Reported at {
+ #01: ... DMD.cpp ...
+ }
+ Reported again at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+Twice-reported {
+ 1 block in heap block record 3 of 4
+ 80 bytes (77 requested / 3 slop)
+ 0.66% of the heap (1.98% cumulative)
+ 29.41% of twice-reported (88.24% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+ Reported at {
+ #01: ... DMD.cpp ...
+ }
+ Reported again at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+Twice-reported {
+ 1 block in heap block record 4 of 4
+ 32 bytes (30 requested / 2 slop)
+ 0.26% of the heap (2.25% cumulative)
+ 11.76% of twice-reported (100.00% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+ Reported at {
+ #01: ... DMD.cpp ...
+ }
+ Reported again at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+#-----------------------------------------------------------------
+
+Unreported {
+ 9 blocks in heap block record 1 of 3
+ 1,008 bytes (900 requested / 108 slop)
+ Individual block sizes: 112 x 9
+ 8.33% of the heap (8.33% cumulative)
+ 81.82% of unreported (81.82% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+Unreported {
+ 2 blocks in heap block record 2 of 3
+ 112 bytes (112 requested / 0 slop)
+ Individual block sizes: 64; 48
+ 0.93% of the heap (9.26% cumulative)
+ 9.09% of unreported (90.91% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+Unreported {
+ 2 blocks in heap block record 3 of 3
+ 112 bytes (112 requested / 0 slop)
+ Individual block sizes: 64; 48
+ 0.93% of the heap (10.19% cumulative)
+ 9.09% of unreported (100.00% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+#-----------------------------------------------------------------
+
+Once-reported {
+ 1 block in heap block record 1 of 11
+ 8,192 bytes (7,169 requested / 1,023 slop)
+ 67.72% of the heap (67.72% cumulative)
+ 77.34% of once-reported (77.34% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+ Reported at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+Once-reported {
+ 1 block in heap block record 2 of 11
+ 1,024 bytes (1,023 requested / 1 slop)
+ 8.47% of the heap (76.19% cumulative)
+ 9.67% of once-reported (87.01% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+ Reported at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+Once-reported {
+ 1 block in heap block record 3 of 11
+ 512 bytes (512 requested / 0 slop)
+ 4.23% of the heap (80.42% cumulative)
+ 4.83% of once-reported (91.84% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+ Reported at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+Once-reported {
+ 2 blocks in heap block record 4 of 11
+ 240 bytes (240 requested / 0 slop)
+ Individual block sizes: 128; 112
+ 1.98% of the heap (82.41% cumulative)
+ 2.27% of once-reported (94.11% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+ Reported at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+Once-reported {
+ 2 blocks in heap block record 5 of 11
+ 240 bytes (240 requested / 0 slop)
+ Individual block sizes: 128; 112
+ 1.98% of the heap (84.39% cumulative)
+ 2.27% of once-reported (96.37% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+ Reported at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+Once-reported {
+ 1 block in heap block record 6 of 11
+ 96 bytes (96 requested / 0 slop)
+ 0.79% of the heap (85.19% cumulative)
+ 0.91% of once-reported (97.28% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+ Reported at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+Once-reported {
+ 1 block in heap block record 7 of 11
+ 96 bytes (96 requested / 0 slop)
+ 0.79% of the heap (85.98% cumulative)
+ 0.91% of once-reported (98.19% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+ Reported at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+Once-reported {
+ 1 block in heap block record 8 of 11
+ 80 bytes (80 requested / 0 slop)
+ 0.66% of the heap (86.64% cumulative)
+ 0.76% of once-reported (98.94% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+ Reported at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+Once-reported {
+ 1 block in heap block record 9 of 11
+ 80 bytes (80 requested / 0 slop)
+ 0.66% of the heap (87.30% cumulative)
+ 0.76% of once-reported (99.70% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+ Reported at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+Once-reported {
+ 1 block in heap block record 10 of 11
+ 16 bytes (16 requested / 0 slop)
+ 0.13% of the heap (87.43% cumulative)
+ 0.15% of once-reported (99.85% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+ Reported at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+Once-reported {
+ 1 block in heap block record 11 of 11
+ 16 bytes (10 requested / 6 slop)
+ 0.13% of the heap (87.57% cumulative)
+ 0.15% of once-reported (100.00% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+ Reported at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+#-----------------------------------------------------------------
+
+Summary {
+ Total: 12,096 bytes (100.00%) in 30 blocks (100.00%)
+ Unreported: 1,232 bytes ( 10.19%) in 13 blocks ( 43.33%)
+ Once-reported: 10,592 bytes ( 87.57%) in 13 blocks ( 43.33%)
+ Twice-reported: 272 bytes ( 2.25%) in 4 blocks ( 13.33%)
+}
+
diff --git a/memory/replace/dmd/test/complete-full1-live-expected.txt b/memory/replace/dmd/test/complete-full1-live-expected.txt
new file mode 100644
index 0000000000..eaa1883e1f
--- /dev/null
+++ b/memory/replace/dmd/test/complete-full1-live-expected.txt
@@ -0,0 +1,127 @@
+#-----------------------------------------------------------------
+# dmd.py --filter-stacks-for-testing -o complete-full1-live-actual.txt complete-full1-live.json
+
+Invocation {
+ $DMD = '--mode=live --stacks=full --show-dump-stats=yes'
+ Mode = 'live'
+}
+
+#-----------------------------------------------------------------
+
+Live {
+ 1 block in heap block record 1 of 12
+ 8,192 bytes (7,169 requested / 1,023 slop)
+ 67.72% of the heap (67.72% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+Live {
+ 1 block in heap block record 2 of 12
+ 1,024 bytes (1,023 requested / 1 slop)
+ 8.47% of the heap (76.19% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+Live {
+ 9 blocks in heap block record 3 of 12
+ 1,008 bytes (900 requested / 108 slop)
+ Individual block sizes: 112 x 9
+ 8.33% of the heap (84.52% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+Live {
+ 6 blocks in heap block record 4 of 12
+ 528 bytes (528 requested / 0 slop)
+ Individual block sizes: 128; 112; 96; 80; 64; 48
+ 4.37% of the heap (88.89% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+Live {
+ 6 blocks in heap block record 5 of 12
+ 528 bytes (528 requested / 0 slop)
+ Individual block sizes: 128; 112; 96; 80; 64; 48
+ 4.37% of the heap (93.25% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+Live {
+ 1 block in heap block record 6 of 12
+ 512 bytes (512 requested / 0 slop)
+ 4.23% of the heap (97.49% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+Live {
+ 1 block in heap block record 7 of 12
+ 80 bytes (79 requested / 1 slop)
+ 0.66% of the heap (98.15% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+Live {
+ 1 block in heap block record 8 of 12
+ 80 bytes (78 requested / 2 slop)
+ 0.66% of the heap (98.81% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+Live {
+ 1 block in heap block record 9 of 12
+ 80 bytes (77 requested / 3 slop)
+ 0.66% of the heap (99.47% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+Live {
+ 1 block in heap block record 10 of 12
+ 32 bytes (30 requested / 2 slop)
+ 0.26% of the heap (99.74% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+Live {
+ 1 block in heap block record 11 of 12
+ 16 bytes (16 requested / 0 slop)
+ 0.13% of the heap (99.87% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+Live {
+ 1 block in heap block record 12 of 12
+ 16 bytes (10 requested / 6 slop)
+ 0.13% of the heap (100.00% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+#-----------------------------------------------------------------
+
+Summary {
+ Total: 12,096 bytes in 30 blocks
+}
+
diff --git a/memory/replace/dmd/test/complete-full2-cumulative-expected.txt b/memory/replace/dmd/test/complete-full2-cumulative-expected.txt
new file mode 100644
index 0000000000..5a225b9b8e
--- /dev/null
+++ b/memory/replace/dmd/test/complete-full2-cumulative-expected.txt
@@ -0,0 +1,173 @@
+#-----------------------------------------------------------------
+# dmd.py --filter-stacks-for-testing -o complete-full2-cumulative-actual.txt complete-full2-cumulative.json
+
+Invocation {
+ $DMD = '--mode=cumulative --stacks=full --show-dump-stats=yes'
+ Mode = 'cumulative'
+}
+
+#-----------------------------------------------------------------
+
+Cumulative {
+ 100 blocks in heap block record 1 of 17
+ 12,800 bytes (12,800 requested / 0 slop)
+ Individual block sizes: 128 x 100
+ 42.37% of the heap (42.37% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+Cumulative {
+ 1 block in heap block record 2 of 17
+ 8,192 bytes (7,169 requested / 1,023 slop)
+ 27.12% of the heap (69.49% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+Cumulative {
+ 1 block in heap block record 3 of 17
+ 4,096 bytes (4,096 requested / 0 slop)
+ 13.56% of the heap (83.05% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+Cumulative {
+ 10 blocks in heap block record 4 of 17
+ 1,120 bytes (1,000 requested / 120 slop)
+ Individual block sizes: 112 x 10
+ 3.71% of the heap (86.76% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+Cumulative {
+ 1 block in heap block record 5 of 17
+ 1,024 bytes (1,024 requested / 0 slop)
+ 3.39% of the heap (90.15% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+Cumulative {
+ 1 block in heap block record 6 of 17
+ 1,024 bytes (1,023 requested / 1 slop)
+ 3.39% of the heap (93.54% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+Cumulative {
+ 6 blocks in heap block record 7 of 17
+ 528 bytes (528 requested / 0 slop)
+ Individual block sizes: 128; 112; 96; 80; 64; 48
+ 1.75% of the heap (95.29% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+Cumulative {
+ 6 blocks in heap block record 8 of 17
+ 528 bytes (528 requested / 0 slop)
+ Individual block sizes: 128; 112; 96; 80; 64; 48
+ 1.75% of the heap (97.03% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+Cumulative {
+ 1 block in heap block record 9 of 17
+ 512 bytes (512 requested / 0 slop)
+ 1.69% of the heap (98.73% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+Cumulative {
+ 1 block in heap block record 10 of 17
+ 80 bytes (79 requested / 1 slop)
+ 0.26% of the heap (98.99% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+Cumulative {
+ 1 block in heap block record 11 of 17
+ 80 bytes (78 requested / 2 slop)
+ 0.26% of the heap (99.26% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+Cumulative {
+ 1 block in heap block record 12 of 17
+ 80 bytes (77 requested / 3 slop)
+ 0.26% of the heap (99.52% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+Cumulative {
+ 1 block in heap block record 13 of 17
+ 64 bytes (64 requested / 0 slop)
+ 0.21% of the heap (99.74% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+Cumulative {
+ 1 block in heap block record 14 of 17
+ 32 bytes (30 requested / 2 slop)
+ 0.11% of the heap (99.84% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+Cumulative {
+ 1 block in heap block record 15 of 17
+ 16 bytes (16 requested / 0 slop)
+ 0.05% of the heap (99.89% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+Cumulative {
+ 1 block in heap block record 16 of 17
+ 16 bytes (16 requested / 0 slop)
+ 0.05% of the heap (99.95% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+Cumulative {
+ 1 block in heap block record 17 of 17
+ 16 bytes (10 requested / 6 slop)
+ 0.05% of the heap (100.00% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+#-----------------------------------------------------------------
+
+Summary {
+ Total: 30,208 bytes in 135 blocks
+}
+
diff --git a/memory/replace/dmd/test/complete-full2-dark-matter-expected.txt b/memory/replace/dmd/test/complete-full2-dark-matter-expected.txt
new file mode 100644
index 0000000000..5f9585a8c6
--- /dev/null
+++ b/memory/replace/dmd/test/complete-full2-dark-matter-expected.txt
@@ -0,0 +1,140 @@
+#-----------------------------------------------------------------
+# dmd.py --filter-stacks-for-testing -o complete-full2-dark-matter-actual.txt complete-full2-dark-matter.json
+
+Invocation {
+ $DMD = '--mode=dark-matter --stacks=full --show-dump-stats=yes'
+ Mode = 'dark-matter'
+}
+
+#-----------------------------------------------------------------
+
+Twice-reported {
+ 1 block in heap block record 1 of 2
+ 80 bytes (77 requested / 3 slop)
+ 2.81% of the heap (2.81% cumulative)
+ 83.33% of twice-reported (83.33% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+ Reported at {
+ #01: ... DMD.cpp ...
+ }
+ Reported again at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+Twice-reported {
+ 1 block in heap block record 2 of 2
+ 16 bytes (16 requested / 0 slop)
+ 0.56% of the heap (3.37% cumulative)
+ 16.67% of twice-reported (100.00% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+ Reported at {
+ #01: ... DMD.cpp ...
+ }
+ Reported again at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+#-----------------------------------------------------------------
+
+Unreported {
+ 9 blocks in heap block record 1 of 3
+ 1,008 bytes (900 requested / 108 slop)
+ Individual block sizes: 112 x 9
+ 35.39% of the heap (35.39% cumulative)
+ 48.84% of unreported (48.84% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+Unreported {
+ 6 blocks in heap block record 2 of 3
+ 528 bytes (528 requested / 0 slop)
+ Individual block sizes: 128; 112; 96; 80; 64; 48
+ 18.54% of the heap (53.93% cumulative)
+ 25.58% of unreported (74.42% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+Unreported {
+ 6 blocks in heap block record 3 of 3
+ 528 bytes (528 requested / 0 slop)
+ Individual block sizes: 128; 112; 96; 80; 64; 48
+ 18.54% of the heap (72.47% cumulative)
+ 25.58% of unreported (100.00% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+#-----------------------------------------------------------------
+
+Once-reported {
+ 1 block in heap block record 1 of 4
+ 512 bytes (512 requested / 0 slop)
+ 17.98% of the heap (17.98% cumulative)
+ 74.42% of once-reported (74.42% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+ Reported at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+Once-reported {
+ 1 block in heap block record 2 of 4
+ 80 bytes (79 requested / 1 slop)
+ 2.81% of the heap (20.79% cumulative)
+ 11.63% of once-reported (86.05% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+ Reported at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+Once-reported {
+ 1 block in heap block record 3 of 4
+ 80 bytes (78 requested / 2 slop)
+ 2.81% of the heap (23.60% cumulative)
+ 11.63% of once-reported (97.67% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+ Reported at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+Once-reported {
+ 1 block in heap block record 4 of 4
+ 16 bytes (10 requested / 6 slop)
+ 0.56% of the heap (24.16% cumulative)
+ 2.33% of once-reported (100.00% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+ Reported at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+#-----------------------------------------------------------------
+
+Summary {
+ Total: 2,848 bytes (100.00%) in 27 blocks (100.00%)
+ Unreported: 2,064 bytes ( 72.47%) in 21 blocks ( 77.78%)
+ Once-reported: 688 bytes ( 24.16%) in 4 blocks ( 14.81%)
+ Twice-reported: 96 bytes ( 3.37%) in 2 blocks ( 7.41%)
+}
+
diff --git a/memory/replace/dmd/test/complete-partial-live-expected.txt b/memory/replace/dmd/test/complete-partial-live-expected.txt
new file mode 100644
index 0000000000..e7f27b0ee6
--- /dev/null
+++ b/memory/replace/dmd/test/complete-partial-live-expected.txt
@@ -0,0 +1,56 @@
+#-----------------------------------------------------------------
+# dmd.py --filter-stacks-for-testing -o complete-partial-live-actual.txt complete-partial-live.json
+
+Invocation {
+ $DMD = '--mode=live'
+ Mode = 'live'
+}
+
+#-----------------------------------------------------------------
+
+Live {
+ 9,531 blocks in heap block record 1 of 4
+ 9,759,744 bytes (9,759,744 requested / 0 slop)
+ Individual block sizes: 1,024 x 9,531
+ 83.56% of the heap (83.56% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+Live {
+ 16,822 blocks in heap block record 2 of 4
+ 1,510,672 bytes (1,510,672 requested / 0 slop)
+ Individual block sizes: 1,024 x 469; 128 x 6,864; 16 x 9,489
+ 12.93% of the heap (96.49% cumulative)
+ Allocated at {
+ #01: (no stack trace recorded due to --stacks=partial)
+ }
+}
+
+Live {
+ 3,136 blocks in heap block record 3 of 4
+ 401,408 bytes (401,408 requested / 0 slop)
+ Individual block sizes: 128 x 3,136
+ 3.44% of the heap (99.93% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+Live {
+ 511 blocks in heap block record 4 of 4
+ 8,176 bytes (8,176 requested / 0 slop)
+ Individual block sizes: 16 x 511
+ 0.07% of the heap (100.00% cumulative)
+ Allocated at {
+ #01: ... DMD.cpp ...
+ }
+}
+
+#-----------------------------------------------------------------
+
+Summary {
+ Total: 11,680,000 bytes in 30,000 blocks
+}
+
diff --git a/memory/replace/dmd/test/moz.build b/memory/replace/dmd/test/moz.build
new file mode 100644
index 0000000000..d6ec431c70
--- /dev/null
+++ b/memory/replace/dmd/test/moz.build
@@ -0,0 +1,26 @@
+# -*- 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/.
+
+GeckoSimplePrograms(
+ [
+ "SmokeDMD",
+ ],
+ linkage=None,
+)
+
+# See the comment at the top of SmokeDMD.cpp:RunTests().
+if CONFIG["CC_TYPE"] == "clang-cl":
+ CXXFLAGS += ["-Od", "-clang:-fno-lto"]
+else:
+ CXXFLAGS += ["-O0", "-fno-lto"]
+
+DEFINES["MOZ_NO_MOZALLOC"] = True
+
+DisableStlWrapping()
+
+XPCSHELL_TESTS_MANIFESTS += [
+ "xpcshell.ini",
+]
diff --git a/memory/replace/dmd/test/scan-test.py b/memory/replace/dmd/test/scan-test.py
new file mode 100644
index 0000000000..c282b02693
--- /dev/null
+++ b/memory/replace/dmd/test/scan-test.py
@@ -0,0 +1,102 @@
+#! /usr/bin/env 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/.
+
+"""Testing for the JSON file emitted by DMD heap scan mode when running SmokeDMD."""
+
+import argparse
+import gzip
+import json
+import sys
+
+# The DMD output version this script handles.
+outputVersion = 5
+
+
+def parseCommandLine():
+ description = """
+Ensure that DMD heap scan mode creates the correct output when run with SmokeDMD.
+This is only for testing. Input files can be gzipped.
+"""
+ p = argparse.ArgumentParser(description=description)
+
+ p.add_argument(
+ "--clamp-contents",
+ action="store_true",
+ help="expect that the contents of the JSON input file have had "
+ "their addresses clamped",
+ )
+
+ p.add_argument("input_file", help="a file produced by DMD")
+
+ return p.parse_args(sys.argv[1:])
+
+
+def checkScanContents(contents, expected):
+ if len(contents) != len(expected):
+ raise Exception(
+ "Expected "
+ + str(len(expected))
+ + " things in contents but found "
+ + str(len(contents))
+ )
+
+ for i in range(len(expected)):
+ if contents[i] != expected[i]:
+ raise Exception(
+ "Expected to find "
+ + expected[i]
+ + " at offset "
+ + str(i)
+ + " but found "
+ + contents[i]
+ )
+
+
+def main():
+ args = parseCommandLine()
+
+ # Handle gzipped input if necessary.
+ isZipped = args.input_file.endswith(".gz")
+ opener = gzip.open if isZipped else open
+
+ with opener(args.input_file, "rb") as f:
+ j = json.load(f)
+
+ if j["version"] != outputVersion:
+ raise Exception("'version' property isn't '{:d}'".format(outputVersion))
+
+ invocation = j["invocation"]
+
+ mode = invocation["mode"]
+ if mode != "scan":
+ raise Exception("bad 'mode' property: '{:s}'".format(mode))
+
+ blockList = j["blockList"]
+
+ if len(blockList) != 1:
+ raise Exception("Expected only one block")
+
+ b = blockList[0]
+
+ # The expected values are based on hard-coded values in SmokeDMD.cpp.
+ if args.clamp_contents:
+ expected = ["0", "0", "0", b["addr"], b["addr"]]
+ else:
+ addr = int(b["addr"], 16)
+ expected = [
+ "123",
+ "0",
+ str(format(addr - 1, "x")),
+ b["addr"],
+ str(format(addr + 1, "x")),
+ "0",
+ ]
+
+ checkScanContents(b["contents"], expected)
+
+
+if __name__ == "__main__":
+ main()
diff --git a/memory/replace/dmd/test/script-diff-dark-matter-expected.txt b/memory/replace/dmd/test/script-diff-dark-matter-expected.txt
new file mode 100644
index 0000000000..b1fc28bac5
--- /dev/null
+++ b/memory/replace/dmd/test/script-diff-dark-matter-expected.txt
@@ -0,0 +1,127 @@
+#-----------------------------------------------------------------
+# dmd.py --filter-stacks-for-testing -o script-diff-dark-matter-actual.txt script-diff-dark-matter1.json script-diff-dark-matter2.json
+
+Invocation 1 {
+ $DMD = '--mode=dark-matter'
+ Mode = 'dark-matter'
+}
+
+Invocation 2 {
+ $DMD = '1'
+ Mode = 'dark-matter'
+}
+
+#-----------------------------------------------------------------
+
+Twice-reported {
+ -1 blocks in heap block record 1 of 1
+ -1,088 bytes (-1,064 requested / -24 slop)
+ Individual block sizes: -1,024; -127; 63
+ 15.46% of the heap (15.46% cumulative)
+ 100.00% of twice-reported (100.00% cumulative)
+ Allocated at {
+ #01: F (F.cpp:99)
+ }
+ Reported at {
+ #01: R1 (R1.cpp:99)
+ }
+ Reported again at {
+ #01: R2 (R2.cpp:99)
+ }
+}
+
+#-----------------------------------------------------------------
+
+Unreported {
+ 4 blocks in heap block record 1 of 5
+ 16,384 bytes (16,384 requested / 0 slop)
+ Individual block sizes: 4,096 x 4
+ -232.76% of the heap (-232.76% cumulative)
+ 371.01% of unreported (371.01% cumulative)
+ Allocated at {
+ #01: E (E.cpp:99)
+ }
+}
+
+Unreported {
+ 7 blocks in heap block record 2 of 5
+ -11,968 bytes (-12,016 requested / 48 slop)
+ Individual block sizes: -15,360; 2,048; 512 x 2; 128; -127; 64 x 4; 63
+ 170.02% of the heap (-62.74% cumulative)
+ -271.01% of unreported (100.00% cumulative)
+ Allocated at {
+ #01: F (F.cpp:99)
+ }
+}
+
+Unreported {
+ 0 blocks in heap block record 3 of 5
+ 0 bytes (-384 requested / 384 slop)
+ Individual block sizes: (no change)
+ -0.00% of the heap (-62.74% cumulative)
+ 0.00% of unreported (100.00% cumulative)
+ Allocated at {
+ #01: C (C.cpp:99)
+ }
+}
+
+Unreported {
+ -2 blocks in heap block record 4 of 5
+ 0 bytes (0 requested / 0 slop)
+ Individual block sizes: 8,192 x 2; -4,096 x 4
+ -0.00% of the heap (-62.74% cumulative)
+ 0.00% of unreported (100.00% cumulative)
+ Allocated at {
+ #01: B (B.cpp:99)
+ }
+}
+
+Unreported {
+ 0 blocks in heap block record 5 of 5
+ 0 bytes (0 requested / 0 slop)
+ Individual block sizes: 20,480; -16,384; -8,192; 4,096
+ -0.00% of the heap (-62.74% cumulative)
+ 0.00% of unreported (100.00% cumulative)
+ Allocated at {
+ #01: (no stack trace recorded due to --stacks=partial)
+ }
+}
+
+#-----------------------------------------------------------------
+
+Once-reported {
+ -3 blocks in heap block record 1 of 2
+ -10,240 bytes (-10,192 requested / -48 slop)
+ Individual block sizes: -4,096 x 2; -2,048
+ 145.48% of the heap (145.48% cumulative)
+ 98.77% of once-reported (98.77% cumulative)
+ Allocated at {
+ #01: D (D.cpp:99)
+ }
+ Reported at {
+ #01: R1 (R1.cpp:99)
+ }
+}
+
+Once-reported {
+ -1 blocks in heap block record 2 of 2
+ -127 bytes (-151 requested / 24 slop)
+ 1.80% of the heap (147.28% cumulative)
+ 1.23% of once-reported (100.00% cumulative)
+ Allocated at {
+ #01: F (F.cpp:99)
+ }
+ Reported at {
+ #01: R1 (R1.cpp:99)
+ }
+}
+
+#-----------------------------------------------------------------
+
+Summary {
+ Total: -7,039 bytes (100.00%) in 4 blocks (100.00%)
+ Unreported: 4,416 bytes (-62.74%) in 9 blocks (225.00%)
+ Once-reported: -10,367 bytes (147.28%) in -4 blocks (-100.00%)
+ Twice-reported: -1,088 bytes ( 15.46%) in -1 blocks (-25.00%)
+}
+
diff --git a/memory/replace/dmd/test/script-diff-dark-matter1.json b/memory/replace/dmd/test/script-diff-dark-matter1.json
new file mode 100644
index 0000000000..1175394150
--- /dev/null
+++ b/memory/replace/dmd/test/script-diff-dark-matter1.json
@@ -0,0 +1,51 @@
+{
+ "version": 5,
+ "invocation": {
+ "dmdEnvVar": "--mode=dark-matter",
+ "mode": "dark-matter"
+ },
+ "blockList": [
+ { "req": 4096, "alloc": "A", "num": 4 },
+
+ { "req": 4096, "alloc": "B", "num": 3 },
+ { "req": 4096, "alloc": "B" },
+
+ { "req": 4096, "alloc": "C", "num": 2 },
+ { "req": 4096, "alloc": "C", "num": 2 },
+
+ { "req": 4096, "alloc": "D", "reps": ["R1"], "num": 2 },
+ { "req": 2000, "slop": 48, "alloc": "D", "reps": ["R1"] },
+
+ { "req": 15360, "alloc": "F" },
+ { "req": 512, "alloc": "F", "num": 2 },
+ { "req": 127, "alloc": "F" },
+ { "req": 1024, "alloc": "F", "reps": ["R1"] },
+ { "req": 127, "alloc": "F", "reps": ["R1"] },
+ { "req": 1000, "slop": 24, "alloc": "F", "reps": ["R1", "R2"] },
+ { "req": 127, "alloc": "F", "reps": ["R1", "R2"] },
+
+ { "req": 4096 },
+ { "req": 8192 },
+ { "req": 16384 }
+ ],
+ "traceTable": {
+ "A": ["AA"],
+ "B": ["BB"],
+ "C": ["CC"],
+ "D": ["DD"],
+ "E": ["EE"],
+ "F": ["FF"],
+ "R1": ["RR1"],
+ "R2": ["RR2"]
+ },
+ "frameTable": {
+ "AA": "#00: A (A.cpp:99)",
+ "BB": "#00: B (B.cpp:99)",
+ "CC": "#00: C (C.cpp:99)",
+ "DD": "#00: D (D.cpp:99)",
+ "EE": "#00: E (E.cpp:99)",
+ "FF": "#00: F (F.cpp:99)",
+ "RR1": "#00: R1 (R1.cpp:99)",
+ "RR2": "#00: R2 (R2.cpp:99)"
+ }
+}
diff --git a/memory/replace/dmd/test/script-diff-dark-matter2.json b/memory/replace/dmd/test/script-diff-dark-matter2.json
new file mode 100644
index 0000000000..2c3061223f
--- /dev/null
+++ b/memory/replace/dmd/test/script-diff-dark-matter2.json
@@ -0,0 +1,51 @@
+{
+ "version": 5,
+ "invocation": {
+ "dmdEnvVar": "1",
+ "mode": "dark-matter"
+ },
+ "blockList": [
+ { "req": 4096, "alloc": "A", "num": 4 },
+
+ { "req": 8192, "alloc": "B" },
+ { "req": 8192, "alloc": "B" },
+
+ { "req": 4000, "slop": 96, "alloc": "C", "num": 4 },
+
+ { "req": 4096, "alloc": "E", "num": 4 },
+
+ { "req": 2000, "slop": 48, "alloc": "F" },
+ { "req": 1000, "slop": 24, "alloc": "F", "reps": ["R1"] },
+ { "req": 512, "alloc": "F" },
+ { "req": 512, "alloc": "F" },
+ { "req": 512, "alloc": "F" },
+ { "req": 512, "alloc": "F" },
+ { "req": 128, "alloc": "F" },
+ { "req": 63, "alloc": "F", "reps": ["R1", "R2"] },
+ { "req": 64, "alloc": "F", "num": 4 },
+ { "req": 63, "alloc": "F" },
+
+ { "req": 4096, "num": 2 },
+ { "req": 20480 }
+ ],
+ "traceTable": {
+ "A": ["AA"],
+ "B": ["BB"],
+ "C": ["CC"],
+ "D": ["DD"],
+ "E": ["EE"],
+ "F": ["FF"],
+ "R1": ["RR1"],
+ "R2": ["RR2"]
+ },
+ "frameTable": {
+ "AA": "#00: A (A.cpp:99)",
+ "BB": "#00: B (B.cpp:99)",
+ "CC": "#00: C (C.cpp:99)",
+ "DD": "#00: D (D.cpp:99)",
+ "EE": "#00: E (E.cpp:99)",
+ "FF": "#00: F (F.cpp:99)",
+ "RR1": "#00: R1 (R1.cpp:99)",
+ "RR2": "#00: R2 (R2.cpp:99)"
+ }
+}
diff --git a/memory/replace/dmd/test/script-diff-live-expected.txt b/memory/replace/dmd/test/script-diff-live-expected.txt
new file mode 100644
index 0000000000..20208c0768
--- /dev/null
+++ b/memory/replace/dmd/test/script-diff-live-expected.txt
@@ -0,0 +1,81 @@
+#-----------------------------------------------------------------
+# dmd.py --filter-stacks-for-testing -o script-diff-live-actual.txt script-diff-live1.json script-diff-live2.json
+
+Invocation 1 {
+ $DMD = '--mode=live'
+ Mode = 'live'
+}
+
+Invocation 2 {
+ $DMD = '--mode=live --stacks=partial'
+ Mode = 'live'
+}
+
+#-----------------------------------------------------------------
+
+Live {
+ 4 blocks in heap block record 1 of 6
+ 16,384 bytes (16,384 requested / 0 slop)
+ Individual block sizes: 4,096 x 4
+ -232.76% of the heap (-232.76% cumulative)
+ Allocated at {
+ #01: E (E.cpp:99)
+ }
+}
+
+Live {
+ 5 blocks in heap block record 2 of 6
+ -13,183 bytes (-13,231 requested / 48 slop)
+ Individual block sizes: -15,360; 2,048; -1,024; 512 x 2; 128; -127 x 3; 64 x 4; 63 x 2
+ 187.29% of the heap (-45.48% cumulative)
+ Allocated at {
+ #01: F (F.cpp:99)
+ }
+}
+
+Live {
+ -3 blocks in heap block record 3 of 6
+ -10,240 bytes (-10,192 requested / -48 slop)
+ Individual block sizes: -4,096 x 2; -2,048
+ 145.48% of the heap (100.00% cumulative)
+ Allocated at {
+ #01: D (D.cpp:99)
+ }
+}
+
+Live {
+ 0 blocks in heap block record 4 of 6
+ 0 bytes (-384 requested / 384 slop)
+ Individual block sizes: (no change)
+ -0.00% of the heap (100.00% cumulative)
+ Allocated at {
+ #01: C (C.cpp:99)
+ }
+}
+
+Live {
+ -2 blocks in heap block record 5 of 6
+ 0 bytes (0 requested / 0 slop)
+ Individual block sizes: 8,192 x 2; -4,096 x 4
+ -0.00% of the heap (100.00% cumulative)
+ Allocated at {
+ #01: B (B.cpp:99)
+ }
+}
+
+Live {
+ 0 blocks in heap block record 6 of 6
+ 0 bytes (0 requested / 0 slop)
+ Individual block sizes: 20,480; -16,384; -8,192; 4,096
+ -0.00% of the heap (100.00% cumulative)
+ Allocated at {
+ #01: (no stack trace recorded due to --stacks=partial)
+ }
+}
+
+#-----------------------------------------------------------------
+
+Summary {
+ Total: -7,039 bytes in 4 blocks
+}
+
diff --git a/memory/replace/dmd/test/script-diff-live1.json b/memory/replace/dmd/test/script-diff-live1.json
new file mode 100644
index 0000000000..1296b9ea09
--- /dev/null
+++ b/memory/replace/dmd/test/script-diff-live1.json
@@ -0,0 +1,51 @@
+{
+ "version": 5,
+ "invocation": {
+ "dmdEnvVar": "--mode=live",
+ "mode": "live"
+ },
+ "blockList": [
+ { "req": 4096, "alloc": "A", "num": 4 },
+
+ { "req": 4096, "alloc": "B", "num": 4 },
+
+ { "req": 4096, "alloc": "C", "num": 4 },
+
+ { "req": 4096, "alloc": "D" },
+ { "req": 4096, "alloc": "D" },
+ { "req": 2000, "slop": 48, "alloc": "D" },
+
+ { "req": 15360, "alloc": "F" },
+ { "req": 512, "alloc": "F" },
+ { "req": 512, "alloc": "F" },
+ { "req": 127, "alloc": "F" },
+ { "req": 1024, "alloc": "F" },
+ { "req": 127, "alloc": "F" },
+ { "req": 1000, "slop": 24, "alloc": "F" },
+ { "req": 127, "alloc": "F" },
+
+ { "req": 4096 },
+ { "req": 8192 },
+ { "req": 16384 }
+ ],
+ "traceTable": {
+ "A": ["AA"],
+ "B": ["BB"],
+ "C": ["CC"],
+ "D": ["DD"],
+ "E": ["EE"],
+ "F": ["FF"],
+ "R1": ["RR1"],
+ "R2": ["RR2"]
+ },
+ "frameTable": {
+ "AA": "#00: A (A.cpp:99)",
+ "BB": "#00: B (B.cpp:99)",
+ "CC": "#00: C (C.cpp:99)",
+ "DD": "#00: D (D.cpp:99)",
+ "EE": "#00: E (E.cpp:99)",
+ "FF": "#00: F (F.cpp:99)",
+ "RR1": "#00: R1 (R1.cpp:99)",
+ "RR2": "#00: R2 (R2.cpp:99)"
+ }
+}
diff --git a/memory/replace/dmd/test/script-diff-live2.json b/memory/replace/dmd/test/script-diff-live2.json
new file mode 100644
index 0000000000..723ea5ff35
--- /dev/null
+++ b/memory/replace/dmd/test/script-diff-live2.json
@@ -0,0 +1,53 @@
+{
+ "version": 5,
+ "invocation": {
+ "dmdEnvVar": "--mode=live --stacks=partial",
+ "mode": "live"
+ },
+ "blockList": [
+ { "req": 4096, "alloc": "A", "num": 3 },
+ { "req": 4096, "alloc": "A" },
+
+ { "req": 8192, "alloc": "B" },
+ { "req": 8192, "alloc": "B" },
+
+ { "req": 4000, "slop": 96, "alloc": "C", "num": 4 },
+
+ { "req": 4096, "alloc": "E" },
+ { "req": 4096, "alloc": "E" },
+ { "req": 4096, "alloc": "E" },
+ { "req": 4096, "alloc": "E" },
+
+ { "req": 2000, "slop": 48, "alloc": "F" },
+ { "req": 1000, "slop": 24, "alloc": "F" },
+ { "req": 512, "alloc": "F", "num": 4 },
+ { "req": 128, "alloc": "F" },
+ { "req": 63, "alloc": "F" },
+ { "req": 64, "alloc": "F", "num": 4 },
+ { "req": 63, "alloc": "F" },
+
+ { "req": 4096 },
+ { "req": 4096 },
+ { "req": 20480 }
+ ],
+ "traceTable": {
+ "A": ["AA"],
+ "B": ["BB"],
+ "C": ["CC"],
+ "D": ["DD"],
+ "E": ["EE"],
+ "F": ["FF"],
+ "R1": ["RR1"],
+ "R2": ["RR2"]
+ },
+ "frameTable": {
+ "AA": "#00: A (A.cpp:99)",
+ "BB": "#00: B (B.cpp:99)",
+ "CC": "#00: C (C.cpp:99)",
+ "DD": "#00: D (D.cpp:99)",
+ "EE": "#00: E (E.cpp:99)",
+ "FF": "#00: F (F.cpp:99)",
+ "RR1": "#00: R1 (R1.cpp:99)",
+ "RR2": "#00: R2 (R2.cpp:99)"
+ }
+}
diff --git a/memory/replace/dmd/test/script-ignore-alloc-fns-expected.txt b/memory/replace/dmd/test/script-ignore-alloc-fns-expected.txt
new file mode 100644
index 0000000000..9428ef45fb
--- /dev/null
+++ b/memory/replace/dmd/test/script-ignore-alloc-fns-expected.txt
@@ -0,0 +1,72 @@
+#-----------------------------------------------------------------
+# dmd.py --filter-stacks-for-testing -o script-ignore-alloc-fns-actual.txt --ignore-alloc-fns script-ignore-alloc-fns.json
+
+Invocation {
+ $DMD = '1'
+ Mode = 'dark-matter'
+}
+
+#-----------------------------------------------------------------
+
+# no twice-reported heap blocks
+
+#-----------------------------------------------------------------
+
+Unreported {
+ 1 block in heap block record 1 of 4
+ 1,048,576 bytes (1,048,576 requested / 0 slop)
+ 93.22% of the heap (93.22% cumulative)
+ 93.22% of unreported (93.22% cumulative)
+ Allocated at {
+ #01: A (A.cpp:99)
+ }
+}
+
+Unreported {
+ 1 block in heap block record 2 of 4
+ 65,536 bytes (65,536 requested / 0 slop)
+ 5.83% of the heap (99.05% cumulative)
+ 5.83% of unreported (99.05% cumulative)
+ Allocated at {
+ #01: js::jit::JitRuntime::initialize(JSContext*) (Ion.cpp:301)
+ }
+}
+
+Unreported {
+ 1 block in heap block record 3 of 4
+ 8,192 bytes (8,000 requested / 192 slop)
+ 0.73% of the heap (99.78% cumulative)
+ 0.73% of unreported (99.78% cumulative)
+ Allocated at {
+ #01: mozilla::Vector::growStorageBy(unsigned long) (Vector.h:802)
+ #02: D (D.cpp:99)
+ }
+}
+
+Unreported {
+ 1 block in heap block record 4 of 4
+ 2,500 bytes (2,500 requested / 0 slop)
+ 0.22% of the heap (100.00% cumulative)
+ 0.22% of unreported (100.00% cumulative)
+ Allocated at {
+ #01: g_type_create_instance (/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0)
+ #02: not_an_alloc_function_so_alloc_functions_below_here_will_not_be_stripped (blah)
+ #03: replace_posix_memalign (replace_malloc.h:120)
+ #04: ??? (/lib/x86_64-linux-gnu/libglib-2.0.so.0)
+ #05: another_non_alloc_function (blah)
+ }
+}
+
+#-----------------------------------------------------------------
+
+# no once-reported heap blocks
+
+#-----------------------------------------------------------------
+
+Summary {
+ Total: 1,124,804 bytes (100.00%) in 4 blocks (100.00%)
+ Unreported: 1,124,804 bytes (100.00%) in 4 blocks (100.00%)
+ Once-reported: 0 bytes ( 0.00%) in 0 blocks ( 0.00%)
+ Twice-reported: 0 bytes ( 0.00%) in 0 blocks ( 0.00%)
+}
+
diff --git a/memory/replace/dmd/test/script-ignore-alloc-fns.json b/memory/replace/dmd/test/script-ignore-alloc-fns.json
new file mode 100644
index 0000000000..a6c7c8419a
--- /dev/null
+++ b/memory/replace/dmd/test/script-ignore-alloc-fns.json
@@ -0,0 +1,45 @@
+{
+ "version": 5,
+ "invocation": {
+ "dmdEnvVar": "1",
+ "mode": "dark-matter"
+ },
+ "blockList": [
+ { "req": 1048576, "alloc": "A" },
+ { "req": 65536, "alloc": "B" },
+ { "req": 8000, "slop": 192, "alloc": "C" },
+ { "req": 2500, "alloc": "D" }
+ ],
+ "traceTable": {
+ "A": ["AA", "AB", "AC", "AD"],
+ "B": ["BA", "BB", "BC"],
+ "C": ["CA", "CB", "CC", "CD"],
+ "D": ["DA", "DB", "DD", "DD", "DE", "DF", "DG", "DH", "DI", "DJ"]
+ },
+ "frameTable": {
+ "AA": "#00: replace_malloc (DMD.cpp:1106)",
+ "AB": "#00: moz_xmalloc (mozalloc.cpp:68)",
+ "AC": "#00: operator new(unsigned long) (mozalloc.h:208)",
+ "AD": "#00: A (A.cpp:99)",
+
+ "BA": "#00: replace_calloc (DMD.cpp:1125)",
+ "BB": "#00: js_calloc(unsigned long) (Utility.h:107)",
+ "BC": "#06: js::jit::JitRuntime::initialize(JSContext*) (Ion.cpp:301)",
+
+ "CA": "#00: replace_realloc (DMD.cpp:1153)",
+ "CB": "#00: bool* mozilla::MallocAllocPolicy::pod_realloc<bool>(bool*, unsigned long, unsigned long) (AllocPolicy.h:74)",
+ "CC": "#00: mozilla::Vector::growStorageBy(unsigned long) (Vector.h:802)",
+ "CD": "#00: D (D.cpp:99)",
+
+ "DA": "#00: replace_memalign (DMD.cpp:1181)",
+ "DB": "#00: replace_posix_memalign (replace_malloc.h:120)",
+ "DC": "#00: ??? (/lib/x86_64-linux-gnu/libglib-2.0.so.0)",
+ "DD": "#00: g_slice_alloc (/lib/x86_64-linux-gnu/libglib-2.0.so.0)",
+ "DE": "#00: g_slice_alloc0 (/lib/x86_64-linux-gnu/libglib-2.0.so.0)",
+ "DF": "#00: g_type_create_instance (/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0)",
+ "DG": "#00: not_an_alloc_function_so_alloc_functions_below_here_will_not_be_stripped (blah)",
+ "DH": "#00: replace_posix_memalign (replace_malloc.h:120)",
+ "DI": "#00: ??? (/lib/x86_64-linux-gnu/libglib-2.0.so.0)",
+ "DJ": "#00: another_non_alloc_function (blah)"
+ }
+}
diff --git a/memory/replace/dmd/test/script-max-frames-1-expected.txt b/memory/replace/dmd/test/script-max-frames-1-expected.txt
new file mode 100644
index 0000000000..65a00762bb
--- /dev/null
+++ b/memory/replace/dmd/test/script-max-frames-1-expected.txt
@@ -0,0 +1,26 @@
+#-----------------------------------------------------------------
+# dmd.py --filter-stacks-for-testing -o script-max-frames-1-actual.txt --max-frames=1 script-max-frames.json
+
+Invocation {
+ $DMD = '--mode=live --stacks=full'
+ Mode = 'live'
+}
+
+#-----------------------------------------------------------------
+
+Live {
+ 4 blocks in heap block record 1 of 1
+ 4,416 bytes (4,404 requested / 12 slop)
+ Individual block sizes: 4,096; 128; 112; 80
+ 100.00% of the heap (100.00% cumulative)
+ Allocated at {
+ #01: E (E.cpp:99)
+ }
+}
+
+#-----------------------------------------------------------------
+
+Summary {
+ Total: 4,416 bytes in 4 blocks
+}
+
diff --git a/memory/replace/dmd/test/script-max-frames-3-expected.txt b/memory/replace/dmd/test/script-max-frames-3-expected.txt
new file mode 100644
index 0000000000..5df4914738
--- /dev/null
+++ b/memory/replace/dmd/test/script-max-frames-3-expected.txt
@@ -0,0 +1,48 @@
+#-----------------------------------------------------------------
+# dmd.py --filter-stacks-for-testing -o script-max-frames-3-actual.txt --max-frames=3 --no-fix-stacks script-max-frames.json
+
+Invocation {
+ $DMD = '--mode=live --stacks=full'
+ Mode = 'live'
+}
+
+#-----------------------------------------------------------------
+
+Live {
+ 2 blocks in heap block record 1 of 3
+ 4,224 bytes (4,224 requested / 0 slop)
+ Individual block sizes: 4,096; 128
+ 95.65% of the heap (95.65% cumulative)
+ Allocated at {
+ #01: E (E.cpp:99)
+ #02: F (F.cpp:99)
+ #03: G (G.cpp:99)
+ }
+}
+
+Live {
+ 1 block in heap block record 2 of 3
+ 112 bytes (100 requested / 12 slop)
+ 2.54% of the heap (98.19% cumulative)
+ Allocated at {
+ #01: E (E.cpp:99)
+ #02: X (X.cpp:99)
+ #03: Y (Y.cpp:99)
+ }
+}
+
+Live {
+ 1 block in heap block record 3 of 3
+ 80 bytes (80 requested / 0 slop)
+ 1.81% of the heap (100.00% cumulative)
+ Allocated at {
+ #01: E (E.cpp:99)
+ }
+}
+
+#-----------------------------------------------------------------
+
+Summary {
+ Total: 4,416 bytes in 4 blocks
+}
+
diff --git a/memory/replace/dmd/test/script-max-frames-8-expected.txt b/memory/replace/dmd/test/script-max-frames-8-expected.txt
new file mode 100644
index 0000000000..174992d5b8
--- /dev/null
+++ b/memory/replace/dmd/test/script-max-frames-8-expected.txt
@@ -0,0 +1,69 @@
+#-----------------------------------------------------------------
+# dmd.py --filter-stacks-for-testing -o script-max-frames-8-actual.txt script-max-frames.json
+
+Invocation {
+ $DMD = '--mode=live --stacks=full'
+ Mode = 'live'
+}
+
+#-----------------------------------------------------------------
+
+Live {
+ 1 block in heap block record 1 of 4
+ 4,096 bytes (4,096 requested / 0 slop)
+ 92.75% of the heap (92.75% cumulative)
+ Allocated at {
+ #01: E (E.cpp:99)
+ #02: F (F.cpp:99)
+ #03: G (G.cpp:99)
+ #04: H (H.cpp:99)
+ #05: I (I.cpp:99)
+ #06: J (J.cpp:99)
+ #07: K (K.cpp:99)
+ #08: L (L.cpp:99)
+ }
+}
+
+Live {
+ 1 block in heap block record 2 of 4
+ 128 bytes (128 requested / 0 slop)
+ 2.90% of the heap (95.65% cumulative)
+ Allocated at {
+ #01: E (E.cpp:99)
+ #02: F (F.cpp:99)
+ #03: G (G.cpp:99)
+ #04: R (R.cpp:99)
+ #05: S (S.cpp:99)
+ #06: T (T.cpp:99)
+ #07: U (U.cpp:99)
+ #08: V (V.cpp:99)
+ }
+}
+
+Live {
+ 1 block in heap block record 3 of 4
+ 112 bytes (100 requested / 12 slop)
+ 2.54% of the heap (98.19% cumulative)
+ Allocated at {
+ #01: E (E.cpp:99)
+ #02: X (X.cpp:99)
+ #03: Y (Y.cpp:99)
+ #04: Z (Z.cpp:99)
+ }
+}
+
+Live {
+ 1 block in heap block record 4 of 4
+ 80 bytes (80 requested / 0 slop)
+ 1.81% of the heap (100.00% cumulative)
+ Allocated at {
+ #01: E (E.cpp:99)
+ }
+}
+
+#-----------------------------------------------------------------
+
+Summary {
+ Total: 4,416 bytes in 4 blocks
+}
+
diff --git a/memory/replace/dmd/test/script-max-frames.json b/memory/replace/dmd/test/script-max-frames.json
new file mode 100644
index 0000000000..6de17a88c3
--- /dev/null
+++ b/memory/replace/dmd/test/script-max-frames.json
@@ -0,0 +1,43 @@
+{
+ "version": 5,
+ "invocation": {
+ "dmdEnvVar": "--mode=live --stacks=full",
+ "mode": "live"
+ },
+ "blockList": [
+ { "req": 4096, "alloc": "A" },
+ { "req": 128, "alloc": "B" },
+ { "req": 100, "slop": 12, "alloc": "C" },
+ { "req": 80, "alloc": "D" }
+ ],
+ "traceTable": {
+ "A": ["E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P"],
+ "B": ["E", "F", "G", "R", "S", "T", "U", "V"],
+ "C": ["E", "X", "Y", "Z"],
+ "D": ["E"]
+ },
+ "frameTable": {
+ "E": "#00: E (E.cpp:99)",
+ "F": "#00: F (F.cpp:99)",
+ "G": "#00: G (G.cpp:99)",
+ "H": "#00: H (H.cpp:99)",
+ "I": "#00: I (I.cpp:99)",
+ "J": "#00: J (J.cpp:99)",
+ "K": "#00: K (K.cpp:99)",
+ "L": "#00: L (L.cpp:99)",
+ "M": "#00: M (M.cpp:99)",
+ "N": "#00: N (N.cpp:99)",
+ "O": "#00: O (O.cpp:99)",
+ "P": "#00: P (P.cpp:99)",
+ "Q": "#00: Q (Q.cpp:99)",
+ "R": "#00: R (R.cpp:99)",
+ "S": "#00: S (S.cpp:99)",
+ "T": "#00: T (T.cpp:99)",
+ "U": "#00: U (U.cpp:99)",
+ "V": "#00: V (V.cpp:99)",
+ "W": "#00: W (W.cpp:99)",
+ "X": "#00: X (X.cpp:99)",
+ "Y": "#00: Y (Y.cpp:99)",
+ "Z": "#00: Z (Z.cpp:99)"
+ }
+}
diff --git a/memory/replace/dmd/test/script-sort-by-num-blocks-expected.txt b/memory/replace/dmd/test/script-sort-by-num-blocks-expected.txt
new file mode 100644
index 0000000000..8de03d953b
--- /dev/null
+++ b/memory/replace/dmd/test/script-sort-by-num-blocks-expected.txt
@@ -0,0 +1,46 @@
+#-----------------------------------------------------------------
+# dmd.py --filter-stacks-for-testing -o script-sort-by-num-blocks-actual.txt --sort-by=num-blocks script-sort-by.json.gz
+
+Invocation {
+ $DMD = '--mode=live'
+ Mode = 'live'
+}
+
+#-----------------------------------------------------------------
+
+Live {
+ 8 blocks in heap block record 1 of 3
+ 16,384 bytes (8,200 requested / 8,184 slop)
+ Individual block sizes: 2,048 x 8
+ 33.32% of the heap (33.32% cumulative)
+ Allocated at {
+ #01: C (C.cpp:99)
+ }
+}
+
+Live {
+ 5 blocks in heap block record 2 of 3
+ 16,400 bytes (12,016 requested / 4,384 slop)
+ Individual block sizes: 4,096 x 4; 16
+ 33.35% of the heap (66.67% cumulative)
+ Allocated at {
+ #01: B (B.cpp:99)
+ }
+}
+
+Live {
+ 5 blocks in heap block record 3 of 3
+ 16,392 bytes (16,392 requested / 0 slop)
+ Individual block sizes: 4,096 x 4; 8
+ 33.33% of the heap (100.00% cumulative)
+ Allocated at {
+ #01: A (A.cpp:99)
+ }
+}
+
+#-----------------------------------------------------------------
+
+Summary {
+ Total: 49,176 bytes in 18 blocks
+}
+
diff --git a/memory/replace/dmd/test/script-sort-by-req-expected.txt b/memory/replace/dmd/test/script-sort-by-req-expected.txt
new file mode 100644
index 0000000000..3ab21ba8f7
--- /dev/null
+++ b/memory/replace/dmd/test/script-sort-by-req-expected.txt
@@ -0,0 +1,46 @@
+#-----------------------------------------------------------------
+# dmd.py --filter-stacks-for-testing -o script-sort-by-req-actual.txt --sort-by=req --no-fix-stacks script-sort-by.json.gz
+
+Invocation {
+ $DMD = '--mode=live'
+ Mode = 'live'
+}
+
+#-----------------------------------------------------------------
+
+Live {
+ 5 blocks in heap block record 1 of 3
+ 16,392 bytes (16,392 requested / 0 slop)
+ Individual block sizes: 4,096 x 4; 8
+ 33.33% of the heap (33.33% cumulative)
+ Allocated at {
+ #01: A (A.cpp:99)
+ }
+}
+
+Live {
+ 5 blocks in heap block record 2 of 3
+ 16,400 bytes (12,016 requested / 4,384 slop)
+ Individual block sizes: 4,096 x 4; 16
+ 33.35% of the heap (66.68% cumulative)
+ Allocated at {
+ #01: B (B.cpp:99)
+ }
+}
+
+Live {
+ 8 blocks in heap block record 3 of 3
+ 16,384 bytes (8,200 requested / 8,184 slop)
+ Individual block sizes: 2,048 x 8
+ 33.32% of the heap (100.00% cumulative)
+ Allocated at {
+ #01: C (C.cpp:99)
+ }
+}
+
+#-----------------------------------------------------------------
+
+Summary {
+ Total: 49,176 bytes in 18 blocks
+}
+
diff --git a/memory/replace/dmd/test/script-sort-by-slop-expected.txt b/memory/replace/dmd/test/script-sort-by-slop-expected.txt
new file mode 100644
index 0000000000..c325c7ed40
--- /dev/null
+++ b/memory/replace/dmd/test/script-sort-by-slop-expected.txt
@@ -0,0 +1,46 @@
+#-----------------------------------------------------------------
+# dmd.py --filter-stacks-for-testing -o script-sort-by-slop-actual.txt --sort-by=slop script-sort-by.json.gz
+
+Invocation {
+ $DMD = '--mode=live'
+ Mode = 'live'
+}
+
+#-----------------------------------------------------------------
+
+Live {
+ 8 blocks in heap block record 1 of 3
+ 16,384 bytes (8,200 requested / 8,184 slop)
+ Individual block sizes: 2,048 x 8
+ 33.32% of the heap (33.32% cumulative)
+ Allocated at {
+ #01: C (C.cpp:99)
+ }
+}
+
+Live {
+ 5 blocks in heap block record 2 of 3
+ 16,400 bytes (12,016 requested / 4,384 slop)
+ Individual block sizes: 4,096 x 4; 16
+ 33.35% of the heap (66.67% cumulative)
+ Allocated at {
+ #01: B (B.cpp:99)
+ }
+}
+
+Live {
+ 5 blocks in heap block record 3 of 3
+ 16,392 bytes (16,392 requested / 0 slop)
+ Individual block sizes: 4,096 x 4; 8
+ 33.33% of the heap (100.00% cumulative)
+ Allocated at {
+ #01: A (A.cpp:99)
+ }
+}
+
+#-----------------------------------------------------------------
+
+Summary {
+ Total: 49,176 bytes in 18 blocks
+}
+
diff --git a/memory/replace/dmd/test/script-sort-by-usable-expected.txt b/memory/replace/dmd/test/script-sort-by-usable-expected.txt
new file mode 100644
index 0000000000..8239a4759e
--- /dev/null
+++ b/memory/replace/dmd/test/script-sort-by-usable-expected.txt
@@ -0,0 +1,46 @@
+#-----------------------------------------------------------------
+# dmd.py --filter-stacks-for-testing -o script-sort-by-usable-actual.txt --sort-by=usable script-sort-by.json.gz
+
+Invocation {
+ $DMD = '--mode=live'
+ Mode = 'live'
+}
+
+#-----------------------------------------------------------------
+
+Live {
+ 5 blocks in heap block record 1 of 3
+ 16,400 bytes (12,016 requested / 4,384 slop)
+ Individual block sizes: 4,096 x 4; 16
+ 33.35% of the heap (33.35% cumulative)
+ Allocated at {
+ #01: B (B.cpp:99)
+ }
+}
+
+Live {
+ 5 blocks in heap block record 2 of 3
+ 16,392 bytes (16,392 requested / 0 slop)
+ Individual block sizes: 4,096 x 4; 8
+ 33.33% of the heap (66.68% cumulative)
+ Allocated at {
+ #01: A (A.cpp:99)
+ }
+}
+
+Live {
+ 8 blocks in heap block record 3 of 3
+ 16,384 bytes (8,200 requested / 8,184 slop)
+ Individual block sizes: 2,048 x 8
+ 33.32% of the heap (100.00% cumulative)
+ Allocated at {
+ #01: C (C.cpp:99)
+ }
+}
+
+#-----------------------------------------------------------------
+
+Summary {
+ Total: 49,176 bytes in 18 blocks
+}
+
diff --git a/memory/replace/dmd/test/script-sort-by.json.gz b/memory/replace/dmd/test/script-sort-by.json.gz
new file mode 100644
index 0000000000..b2308bab40
--- /dev/null
+++ b/memory/replace/dmd/test/script-sort-by.json.gz
Binary files differ
diff --git a/memory/replace/dmd/test/test_dmd.js b/memory/replace/dmd/test/test_dmd.js
new file mode 100644
index 0000000000..d96444ea05
--- /dev/null
+++ b/memory/replace/dmd/test/test_dmd.js
@@ -0,0 +1,224 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*-*/
+/* vim: set ts=8 sts=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/. */
+
+"use strict";
+
+const { FileUtils } = ChromeUtils.importESModule(
+ "resource://gre/modules/FileUtils.sys.mjs"
+);
+
+// The xpcshell test harness sets PYTHON so we can read it here.
+var gPythonName = Services.env.get("PYTHON");
+
+// If we're testing locally, the executable file is in "CurProcD". Otherwise,
+// it is in another location that we have to find.
+function getExecutable(aFilename) {
+ let file = FileUtils.getFile("CurProcD", [aFilename]);
+ if (!file.exists()) {
+ file = FileUtils.getFile("CurWorkD", []);
+ while (file.path.includes("xpcshell")) {
+ file = file.parent;
+ }
+ file.append("bin");
+ file.append(aFilename);
+ }
+ return file;
+}
+
+var gIsWindows = Services.appinfo.OS === "WINNT";
+var gDmdTestFile = getExecutable("SmokeDMD" + (gIsWindows ? ".exe" : ""));
+
+var gDmdScriptFile = getExecutable("dmd.py");
+
+var gScanTestFile = FileUtils.getFile("CurWorkD", ["scan-test.py"]);
+
+function readFile(aFile) {
+ let fstream = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(
+ Ci.nsIFileInputStream
+ );
+ let cstream = Cc["@mozilla.org/intl/converter-input-stream;1"].createInstance(
+ Ci.nsIConverterInputStream
+ );
+ fstream.init(aFile, -1, 0, 0);
+ cstream.init(fstream, "UTF-8", 0, 0);
+
+ let data = "";
+ let str = {};
+ let read = 0;
+ do {
+ // Read as much as we can and put it in str.value.
+ read = cstream.readString(0xffffffff, str);
+ data += str.value;
+ } while (read != 0);
+
+ cstream.close(); // this closes fstream
+ return data.replace(/\r/g, ""); // normalize line endings
+}
+
+function runProcess(aExeFile, aArgs) {
+ let process = Cc["@mozilla.org/process/util;1"].createInstance(Ci.nsIProcess);
+ process.init(aExeFile);
+ process.run(/* blocking = */ true, aArgs, aArgs.length);
+ return process.exitValue;
+}
+
+function test(aPrefix, aArgs) {
+ // DMD writes the JSON files to CurWorkD, so we do likewise here with
+ // |actualFile| for consistency. It is removed once we've finished.
+ let expectedFile = FileUtils.getFile("CurWorkD", [aPrefix + "-expected.txt"]);
+ let actualFile = FileUtils.getFile("CurWorkD", [aPrefix + "-actual.txt"]);
+
+ // Run dmd.py on the JSON file, producing |actualFile|.
+
+ let args = [
+ gDmdScriptFile.path,
+ "--filter-stacks-for-testing",
+ "-o",
+ actualFile.path,
+ ].concat(aArgs);
+
+ runProcess(new FileUtils.File(gPythonName), args);
+
+ // Compare |expectedFile| with |actualFile|. We produce nice diffs with
+ // /usr/bin/diff on systems that have it (Mac and Linux). Otherwise (Windows)
+ // we do a string compare of the file contents and then print them both if
+ // they don't match.
+
+ let success;
+ try {
+ let rv = runProcess(new FileUtils.File("/usr/bin/diff"), [
+ "-u",
+ expectedFile.path,
+ actualFile.path,
+ ]);
+ success = rv == 0;
+ } catch (e) {
+ let expectedData = readFile(expectedFile);
+ let actualData = readFile(actualFile);
+ success = expectedData === actualData;
+ if (!success) {
+ expectedData = expectedData.split("\n");
+ actualData = actualData.split("\n");
+ for (let i = 0; i < expectedData.length; i++) {
+ print("EXPECTED:" + expectedData[i]);
+ }
+ for (let i = 0; i < actualData.length; i++) {
+ print(" ACTUAL:" + actualData[i]);
+ }
+ }
+ }
+
+ ok(success, aPrefix);
+
+ actualFile.remove(true);
+}
+
+// Run scan-test.py on the JSON file and see if it succeeds.
+function scanTest(aJsonFilePath, aExtraArgs) {
+ let args = [gScanTestFile.path, aJsonFilePath].concat(aExtraArgs);
+
+ return runProcess(new FileUtils.File(gPythonName), args) == 0;
+}
+
+function run_test() {
+ let jsonFile, jsonFile2;
+
+ // These tests do complete end-to-end testing of DMD, i.e. both the C++ code
+ // that generates the JSON output, and the script that post-processes that
+ // output.
+ //
+ // Run these synchronously, because test() updates the complete*.json files
+ // in-place (to fix stacks) when it runs dmd.py, and that's not safe to do
+ // asynchronously.
+
+ Services.env.set("DMD", "1");
+
+ runProcess(gDmdTestFile, []);
+
+ function test2(aTestName, aMode) {
+ let name = "complete-" + aTestName + "-" + aMode;
+ jsonFile = FileUtils.getFile("CurWorkD", [name + ".json"]);
+ test(name, [jsonFile.path]);
+ jsonFile.remove(true);
+ }
+
+ // Please keep this in sync with RunTests() in SmokeDMD.cpp.
+
+ test2("empty", "live");
+ test2("empty", "dark-matter");
+ test2("empty", "cumulative");
+
+ test2("full1", "live");
+ test2("full1", "dark-matter");
+
+ test2("full2", "dark-matter");
+ test2("full2", "cumulative");
+
+ test2("partial", "live");
+
+ // Heap scan testing.
+ jsonFile = FileUtils.getFile("CurWorkD", ["basic-scan.json"]);
+ ok(scanTest(jsonFile.path), "Basic scan test");
+
+ let is64Bit = Services.appinfo.is64Bit;
+ let basicScanFileName = "basic-scan-" + (is64Bit ? "64" : "32");
+ test(basicScanFileName, ["--clamp-contents", jsonFile.path]);
+ ok(
+ scanTest(jsonFile.path, ["--clamp-contents"]),
+ "Scan with address clamping"
+ );
+
+ // Run the generic test a second time to ensure that the first time produced
+ // valid JSON output. "--clamp-contents" is passed in so we don't have to have
+ // more variants of the files.
+ test(basicScanFileName, ["--clamp-contents", jsonFile.path]);
+ jsonFile.remove(true);
+
+ // These tests only test the post-processing script. They use hand-written
+ // JSON files as input. Ideally the JSON files would contain comments
+ // explaining how they work, but JSON doesn't allow comments, so I've put
+ // explanations here.
+
+ // This just tests that stack traces of various lengths are truncated
+ // appropriately. The number of records in the output is different for each
+ // of the tested values.
+ jsonFile = FileUtils.getFile("CurWorkD", ["script-max-frames.json"]);
+ test("script-max-frames-8", [jsonFile.path]); // --max-frames=8 is the default
+ test("script-max-frames-3", [
+ "--max-frames=3",
+ "--no-fix-stacks",
+ jsonFile.path,
+ ]);
+ test("script-max-frames-1", ["--max-frames=1", jsonFile.path]);
+
+ // This file has three records that are shown in a different order for each
+ // of the different sort values. It also tests the handling of gzipped JSON
+ // files.
+ jsonFile = FileUtils.getFile("CurWorkD", ["script-sort-by.json.gz"]);
+ test("script-sort-by-usable", ["--sort-by=usable", jsonFile.path]);
+ test("script-sort-by-req", [
+ "--sort-by=req",
+ "--no-fix-stacks",
+ jsonFile.path,
+ ]);
+ test("script-sort-by-slop", ["--sort-by=slop", jsonFile.path]);
+ test("script-sort-by-num-blocks", ["--sort-by=num-blocks", jsonFile.path]);
+
+ // This file has several real stack traces taken from Firefox execution, each
+ // of which tests a different allocator function (or functions).
+ jsonFile = FileUtils.getFile("CurWorkD", ["script-ignore-alloc-fns.json"]);
+ test("script-ignore-alloc-fns", ["--ignore-alloc-fns", jsonFile.path]);
+
+ // This tests "live"-mode diffs.
+ jsonFile = FileUtils.getFile("CurWorkD", ["script-diff-live1.json"]);
+ jsonFile2 = FileUtils.getFile("CurWorkD", ["script-diff-live2.json"]);
+ test("script-diff-live", [jsonFile.path, jsonFile2.path]);
+
+ // This tests "dark-matter"-mode diffs.
+ jsonFile = FileUtils.getFile("CurWorkD", ["script-diff-dark-matter1.json"]);
+ jsonFile2 = FileUtils.getFile("CurWorkD", ["script-diff-dark-matter2.json"]);
+ test("script-diff-dark-matter", [jsonFile.path, jsonFile2.path]);
+}
diff --git a/memory/replace/dmd/test/xpcshell.ini b/memory/replace/dmd/test/xpcshell.ini
new file mode 100644
index 0000000000..2baeeed270
--- /dev/null
+++ b/memory/replace/dmd/test/xpcshell.ini
@@ -0,0 +1,35 @@
+[DEFAULT]
+support-files =
+ basic-scan-32-expected.txt
+ basic-scan-64-expected.txt
+ complete-empty-live-expected.txt
+ complete-empty-dark-matter-expected.txt
+ complete-empty-cumulative-expected.txt
+ complete-full1-live-expected.txt
+ complete-full1-dark-matter-expected.txt
+ complete-full2-dark-matter-expected.txt
+ complete-full2-cumulative-expected.txt
+ complete-partial-live-expected.txt
+ scan-test.py
+ script-max-frames.json
+ script-max-frames-8-expected.txt
+ script-max-frames-3-expected.txt
+ script-max-frames-1-expected.txt
+ script-sort-by.json.gz
+ script-sort-by-usable-expected.txt
+ script-sort-by-req-expected.txt
+ script-sort-by-slop-expected.txt
+ script-sort-by-num-blocks-expected.txt
+ script-ignore-alloc-fns.json
+ script-ignore-alloc-fns-expected.txt
+ script-diff-live1.json
+ script-diff-live2.json
+ script-diff-live-expected.txt
+ script-diff-dark-matter1.json
+ script-diff-dark-matter2.json
+ script-diff-dark-matter-expected.txt
+
+[test_dmd.js]
+dmd = true
+skip-if =
+ !(os=='linux' || os=='mac' || (os=='win' && !pgo))