Bug 1079660 - DMD: don't call malloc et al. directly in the test. r=glandium.
authorNicholas Nethercote <nnethercote@mozilla.com>
Tue, 07 Oct 2014 21:44:42 -0700
changeset 232956 b820349b5b4666e3ed8c750a58b60e12e8c64ba2
parent 232955 b30e3a050567803de30476019332ec9bd6349023
child 232957 c20e7032aa3b31b897ebe32b7c15e82d7bf480b2
push id4187
push userbhearsum@mozilla.com
push dateFri, 28 Nov 2014 15:29:12 +0000
treeherdermozilla-beta@f23cc6a30c11 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium
bugs1079660
milestone35.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 1079660 - DMD: don't call malloc et al. directly in the test. r=glandium.
memory/replace/dmd/DMD.cpp
--- a/memory/replace/dmd/DMD.cpp
+++ b/memory/replace/dmd/DMD.cpp
@@ -1840,17 +1840,17 @@ AnalyzeReports(JSONWriter& aWriter)
 //---------------------------------------------------------------------------
 
 // 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);
+    a[i] = (char*) replace_malloc(128 - 16*i);
   }
 
   for (int i = 0; i < aSeven - 5; i++) {
     Report(a[i]);                   // reported
   }
   Report(a[2]);                     // reported
   Report(a[3]);                     // reported
   // a[4], a[5] unreported
@@ -1868,19 +1868,19 @@ UseItOrLoseIt(void* aPtr, int aSeven)
 }
 
 // The output from this function feeds into DMD's xpcshell test.
 static void
 RunTestMode(UniquePtr<FpWriteFunc> aF1, UniquePtr<FpWriteFunc> aF2,
             UniquePtr<FpWriteFunc> aF3, UniquePtr<FpWriteFunc> aF4)
 {
   // 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 want a constant value that the compiler can't determine
-  // statically, and we use that in various ways to prevent the above
+  // eliding unused replace_malloc() calls or unrolling loops with fixed
+  // iteration counts. So we want a constant value that the compiler can't
+  // determine statically, and we use that in various ways to prevent the above
   // optimizations from happening.
   //
   // This code always sets |seven| to the value 7. It works because we know
   // that "--mode=test" must be within the DMD environment variable if we reach
   // here, but the compiler almost certainly does not.
   //
   char* env = getenv("DMD");
   char* p1 = strstr(env, "--mode=t");
@@ -1898,105 +1898,104 @@ RunTestMode(UniquePtr<FpWriteFunc> aF1, 
 
   //---------
 
   // AnalyzeReports 2: 1 freed, 9 out of 10 unreported.
   // AnalyzeReports 3: still present and unreported.
   int i;
   char* a = nullptr;
   for (i = 0; i < seven + 3; i++) {
-      a = (char*) malloc(100);
+      a = (char*) replace_malloc(100);
       UseItOrLoseIt(a, seven);
   }
-  free(a);
+  replace_free(a);
 
   // Note: 8 bytes is the smallest requested size that gives consistent
   // behaviour across all platforms with jemalloc.
   // AnalyzeReports 2: reported.
   // AnalyzeReports 3: thrice-reported.
-  char* a2 = (char*) malloc(8);
+  char* a2 = (char*) replace_malloc(8);
   Report(a2);
 
-  // Operator new[].
   // AnalyzeReports 2: reported.
   // AnalyzeReports 3: reportedness carries over, due to ReportOnAlloc.
-  char* b = new char[10];
+  char* b = (char*) replace_malloc(10);
   ReportOnAlloc(b);
 
   // ReportOnAlloc, then freed.
   // AnalyzeReports 2: freed, irrelevant.
   // AnalyzeReports 3: freed, irrelevant.
-  char* b2 = new char;
+  char* b2 = (char*) replace_malloc(1);
   ReportOnAlloc(b2);
-  free(b2);
+  replace_free(b2);
 
   // AnalyzeReports 2: reported 4 times.
   // AnalyzeReports 3: freed, irrelevant.
-  char* c = (char*) calloc(10, 3);
+  char* c = (char*) replace_calloc(10, 3);
   Report(c);
   for (int i = 0; i < seven - 4; i++) {
     Report(c);
   }
 
   // AnalyzeReports 2: ignored.
   // AnalyzeReports 3: irrelevant.
   Report((void*)(intptr_t)i);
 
   // jemalloc rounds this up to 8192.
   // AnalyzeReports 2: reported.
   // AnalyzeReports 3: freed.
-  char* e = (char*) malloc(4096);
-  e = (char*) realloc(e, 4097);
+  char* e = (char*) replace_malloc(4096);
+  e = (char*) replace_realloc(e, 4097);
   Report(e);
 
   // First realloc is like malloc;  second realloc is shrinking.
   // AnalyzeReports 2: reported.
   // AnalyzeReports 3: re-reported.
-  char* e2 = (char*) realloc(nullptr, 1024);
-  e2 = (char*) realloc(e2, 512);
+  char* e2 = (char*) replace_realloc(nullptr, 1024);
+  e2 = (char*) replace_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.
   // AnalyzeReports 2: reported.
   // AnalyzeReports 3: freed, irrelevant.
-  char* e3 = (char*) realloc(nullptr, 1023);
-//e3 = (char*) realloc(e3, 0);
+  char* e3 = (char*) replace_realloc(nullptr, 1023);
+//e3 = (char*) replace_realloc(e3, 0);
   MOZ_ASSERT(e3);
   Report(e3);
 
   // AnalyzeReports 2: freed, irrelevant.
   // AnalyzeReports 3: freed, irrelevant.
-  char* f = (char*) malloc(64);
-  free(f);
+  char* f = (char*) replace_malloc(64);
+  replace_free(f);
 
   // AnalyzeReports 2: ignored.
   // AnalyzeReports 3: irrelevant.
   Report((void*)(intptr_t)0x0);
 
   // AnalyzeReports 2: mixture of reported and unreported.
   // AnalyzeReports 3: all unreported.
   Foo(seven);
   Foo(seven);
 
   // AnalyzeReports 2: twice-reported.
   // AnalyzeReports 3: twice-reported.
-  char* g1 = (char*) malloc(77);
+  char* g1 = (char*) replace_malloc(77);
   ReportOnAlloc(g1);
   ReportOnAlloc(g1);
 
   // AnalyzeReports 2: twice-reported.
   // AnalyzeReports 3: once-reported.
-  char* g2 = (char*) malloc(78);
+  char* g2 = (char*) replace_malloc(78);
   Report(g2);
   ReportOnAlloc(g2);
 
   // AnalyzeReports 2: twice-reported.
   // AnalyzeReports 3: once-reported.
-  char* g3 = (char*) malloc(79);
+  char* g3 = (char*) replace_malloc(79);
   ReportOnAlloc(g3);
   Report(g3);
 
   // All the odd-ball ones.
   // AnalyzeReports 2: all unreported.
   // AnalyzeReports 3: all freed, irrelevant.
   // XXX: no memalign on Mac
 //void* x = memalign(64, 65);           // rounds up to 128
@@ -2013,82 +2012,82 @@ RunTestMode(UniquePtr<FpWriteFunc> aF1, 
   // AnalyzeReports 2.
   JSONWriter writer2(Move(aF2));
   AnalyzeReports(writer2);
 
   //---------
 
   Report(a2);
   Report(a2);
-  free(c);
-  free(e);
+  replace_free(c);
+  replace_free(e);
   Report(e2);
-  free(e3);
-//free(x);
-//free(y);
-//free(z);
+  replace_free(e3);
+//replace_free(x);
+//replace_free(y);
+//replace_free(z);
 
   // AnalyzeReports 3.
   JSONWriter writer3(Move(aF3));
   AnalyzeReports(writer3);
 
   //---------
 
   // Clear all knowledge of existing blocks to give us a clean slate.
   gBlockTable->clear();
 
   gOptions->SetSampleBelowSize(128);
 
   char* s;
 
   // This equals the sample size, and so is reported exactly.  It should be
   // listed before records of the same size that are sampled.
-  s = (char*) malloc(128);
+  s = (char*) replace_malloc(128);
   UseItOrLoseIt(s, seven);
 
   // This exceeds the sample size, and so is reported exactly.
-  s = (char*) malloc(144);
+  s = (char*) replace_malloc(144);
   UseItOrLoseIt(s, seven);
 
   // These together constitute exactly one sample.
   for (int i = 0; i < seven + 9; i++) {
-    s = (char*) malloc(8);
+    s = (char*) replace_malloc(8);
     UseItOrLoseIt(s, seven);
   }
   MOZ_ASSERT(gSmallBlockActualSizeCounter == 0);
 
   // These fall 8 bytes short of a full sample.
   for (int i = 0; i < seven + 8; i++) {
-    s = (char*) malloc(8);
+    s = (char*) replace_malloc(8);
     UseItOrLoseIt(s, seven);
   }
   MOZ_ASSERT(gSmallBlockActualSizeCounter == 120);
 
   // This exceeds the sample size, and so is recorded exactly.
-  s = (char*) malloc(256);
+  s = (char*) replace_malloc(256);
   UseItOrLoseIt(s, seven);
   MOZ_ASSERT(gSmallBlockActualSizeCounter == 120);
 
   // This gets more than to a full sample from the |i < 15| loop above.
-  s = (char*) malloc(96);
+  s = (char*) replace_malloc(96);
   UseItOrLoseIt(s, seven);
   MOZ_ASSERT(gSmallBlockActualSizeCounter == 88);
 
   // This gets to another full sample.
   for (int i = 0; i < seven - 2; i++) {
-    s = (char*) malloc(8);
+    s = (char*) replace_malloc(8);
     UseItOrLoseIt(s, seven);
   }
   MOZ_ASSERT(gSmallBlockActualSizeCounter == 0);
 
   // This allocates 16, 32, ..., 128 bytes, which results in a heap block
   // record that contains a mix of sample and non-sampled blocks, and so should
   // be printed with '~' signs.
   for (int i = 1; i <= seven + 1; i++) {
-    s = (char*) malloc(i * 16);
+    s = (char*) replace_malloc(i * 16);
     UseItOrLoseIt(s, seven);
   }
   MOZ_ASSERT(gSmallBlockActualSizeCounter == 64);
 
   // At the end we're 64 bytes into the current sample so we report ~1,424
   // bytes of allocation overall, which is 64 less than the real value 1,488.
 
   // AnalyzeReports 4.