Title: [177191] trunk/Source/bmalloc
Revision
177191
Author
[email protected]
Date
2014-12-11 16:22:41 -0800 (Thu, 11 Dec 2014)

Log Message

bmalloc should support system memory analysis tools (part 2)
https://bugs.webkit.org/show_bug.cgi?id=139565

Reviewed by Mark Lam.

This patch actually queries the environment to see if memory analysis
tools have been enabled.

* bmalloc/Deallocator.cpp:
(bmalloc::Deallocator::scavenge): Don't process the object log if
we've disabled bmalloc because it will be full of invalid nullptrs.

* bmalloc/Environment.cpp:
(bmalloc::isMallocEnvironmentVariableSet): Test for the list of known
Malloc debugging flags. I also added a plain "Malloc" catch-all for
when you want to disable bmalloc without enabling any kind of funny
business.

It would be slightly nicer just to iterate the list of environment
variables and strstr them, but getenv is the more portable option,
and performance here doesn't really matter.

(bmalloc::isLibgmallocEnabled): Test for the libgmalloc insertion
environment variable.

(bmalloc::Environment::computeIsBmallocEnabled):

Modified Paths

Diff

Modified: trunk/Source/bmalloc/ChangeLog (177190 => 177191)


--- trunk/Source/bmalloc/ChangeLog	2014-12-12 00:18:09 UTC (rev 177190)
+++ trunk/Source/bmalloc/ChangeLog	2014-12-12 00:22:41 UTC (rev 177191)
@@ -1,5 +1,34 @@
 2014-12-11  Geoffrey Garen  <[email protected]>
 
+        bmalloc should support system memory analysis tools (part 2)
+        https://bugs.webkit.org/show_bug.cgi?id=139565
+
+        Reviewed by Mark Lam.
+
+        This patch actually queries the environment to see if memory analysis
+        tools have been enabled.
+
+        * bmalloc/Deallocator.cpp:
+        (bmalloc::Deallocator::scavenge): Don't process the object log if
+        we've disabled bmalloc because it will be full of invalid nullptrs.
+
+        * bmalloc/Environment.cpp:
+        (bmalloc::isMallocEnvironmentVariableSet): Test for the list of known
+        Malloc debugging flags. I also added a plain "Malloc" catch-all for
+        when you want to disable bmalloc without enabling any kind of funny
+        business.
+
+        It would be slightly nicer just to iterate the list of environment
+        variables and strstr them, but getenv is the more portable option,
+        and performance here doesn't really matter.
+
+        (bmalloc::isLibgmallocEnabled): Test for the libgmalloc insertion
+        environment variable.
+
+        (bmalloc::Environment::computeIsBmallocEnabled):
+
+2014-12-11  Geoffrey Garen  <[email protected]>
+
         Try to fix the iOS simulator build.
 
         #include the declaration of malloc / free.

Modified: trunk/Source/bmalloc/bmalloc/Allocator.cpp (177190 => 177191)


--- trunk/Source/bmalloc/bmalloc/Allocator.cpp	2014-12-12 00:18:09 UTC (rev 177190)
+++ trunk/Source/bmalloc/bmalloc/Allocator.cpp	2014-12-12 00:22:41 UTC (rev 177191)
@@ -30,7 +30,7 @@
 #include "PerProcess.h"
 #include "Sizes.h"
 #include <algorithm>
-#include <stdlib.h>
+#include <cstdlib>
 
 using namespace std;
 

Modified: trunk/Source/bmalloc/bmalloc/Deallocator.cpp (177190 => 177191)


--- trunk/Source/bmalloc/bmalloc/Deallocator.cpp	2014-12-12 00:18:09 UTC (rev 177190)
+++ trunk/Source/bmalloc/bmalloc/Deallocator.cpp	2014-12-12 00:22:41 UTC (rev 177191)
@@ -32,7 +32,7 @@
 #include "PerProcess.h"
 #include "SmallChunk.h"
 #include <algorithm>
-#include <stdlib.h>
+#include <cstdlib>
 #include <sys/mman.h>
 
 using namespace std;
@@ -56,7 +56,8 @@
     
 void Deallocator::scavenge()
 {
-    processObjectLog();
+    if (m_isBmallocEnabled)
+        processObjectLog();
 }
 
 void Deallocator::deallocateLarge(void* object)

Modified: trunk/Source/bmalloc/bmalloc/Environment.cpp (177190 => 177191)


--- trunk/Source/bmalloc/bmalloc/Environment.cpp	2014-12-12 00:18:09 UTC (rev 177190)
+++ trunk/Source/bmalloc/bmalloc/Environment.cpp	2014-12-12 00:22:41 UTC (rev 177191)
@@ -24,9 +24,51 @@
  */
 
 #include "Environment.h"
+#include <cstdlib>
+#include <cstring>
 
 namespace bmalloc {
 
+static bool isMallocEnvironmentVariableSet()
+{
+    const char* list[] = {
+        "Malloc",
+        "MallocLogFile",
+        "MallocGuardEdges",
+        "MallocDoNotProtectPrelude",
+        "MallocDoNotProtectPostlude",
+        "MallocStackLogging",
+        "MallocStackLoggingNoCompact",
+        "MallocStackLoggingDirectory",
+        "MallocScribble",
+        "MallocCheckHeapStart",
+        "MallocCheckHeapEach",
+        "MallocCheckHeapSleep",
+        "MallocCheckHeapAbort",
+        "MallocErrorAbort",
+        "MallocCorruptionAbort",
+        "MallocHelp"
+    };
+    size_t size = sizeof(list) / sizeof(const char*);
+    
+    for (size_t i = 0; i < size; ++i) {
+        if (getenv(list[i]))
+            return true;
+    }
+
+    return false;
+}
+
+static bool isLibgmallocEnabled()
+{
+    char* variable = getenv("DYLD_INSERT_LIBRARIES");
+    if (!variable)
+        return false;
+    if (!strstr(variable, "libgmalloc"))
+        return false;
+    return true;
+}
+
 Environment::Environment()
     : m_isBmallocEnabled(computeIsBmallocEnabled())
 {
@@ -34,6 +76,10 @@
 
 bool Environment::computeIsBmallocEnabled()
 {
+    if (isMallocEnvironmentVariableSet())
+        return false;
+    if (isLibgmallocEnabled())
+        return false;
     return true;
 }
 

Modified: trunk/Source/bmalloc/bmalloc/Range.h (177190 => 177191)


--- trunk/Source/bmalloc/bmalloc/Range.h	2014-12-12 00:18:09 UTC (rev 177190)
+++ trunk/Source/bmalloc/bmalloc/Range.h	2014-12-12 00:22:41 UTC (rev 177191)
@@ -26,7 +26,7 @@
 #ifndef Range_h
 #define Range_h
 
-#include <stddef.h>
+#include <cstddef>
 
 namespace bmalloc {
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to