bmalloc: VMHeap should keep a record of all of its VM ranges (for malloc introspection)
authorggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 18 Feb 2015 19:00:16 +0000 (19:00 +0000)
committerggaren@apple.com <ggaren@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 18 Feb 2015 19:00:16 +0000 (19:00 +0000)
https://bugs.webkit.org/show_bug.cgi?id=141759

Reviewed by Andreas Kling.

* bmalloc.xcodeproj/project.pbxproj:
* bmalloc/SuperChunk.h: Added.
(bmalloc::SuperChunk::create):
(bmalloc::SuperChunk::SuperChunk):
(bmalloc::SuperChunk::smallChunk):
(bmalloc::SuperChunk::mediumChunk):
(bmalloc::SuperChunk::largeChunk): Factored out super chunk creation
into a separate class, for clarity and type safety.

* bmalloc/VMHeap.cpp:
(bmalloc::VMHeap::grow):
(bmalloc::VMHeap::allocateSuperChunk): Renamed "allocateSuperChunk" to
"grow" because Andreas found "allocateSuperChunk" to be unclear.

* bmalloc/VMHeap.h: Track all our VM ranges. We will use this information
for malloc introspection.

(bmalloc::VMHeap::allocateSmallPage):
(bmalloc::VMHeap::allocateMediumPage):
(bmalloc::VMHeap::allocateLargeRange): Updated for renames.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@180272 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/bmalloc/ChangeLog
Source/bmalloc/bmalloc.xcodeproj/project.pbxproj
Source/bmalloc/bmalloc/SuperChunk.h [new file with mode: 0644]
Source/bmalloc/bmalloc/VMHeap.cpp
Source/bmalloc/bmalloc/VMHeap.h

index 366f3e3..66ff2b2 100644 (file)
@@ -1,3 +1,31 @@
+2015-02-18  Geoffrey Garen  <ggaren@apple.com>
+
+        bmalloc: VMHeap should keep a record of all of its VM ranges (for malloc introspection)
+        https://bugs.webkit.org/show_bug.cgi?id=141759
+
+        Reviewed by Andreas Kling.
+
+        * bmalloc.xcodeproj/project.pbxproj:
+        * bmalloc/SuperChunk.h: Added.
+        (bmalloc::SuperChunk::create):
+        (bmalloc::SuperChunk::SuperChunk):
+        (bmalloc::SuperChunk::smallChunk):
+        (bmalloc::SuperChunk::mediumChunk):
+        (bmalloc::SuperChunk::largeChunk): Factored out super chunk creation
+        into a separate class, for clarity and type safety.
+
+        * bmalloc/VMHeap.cpp:
+        (bmalloc::VMHeap::grow):
+        (bmalloc::VMHeap::allocateSuperChunk): Renamed "allocateSuperChunk" to
+        "grow" because Andreas found "allocateSuperChunk" to be unclear.
+
+        * bmalloc/VMHeap.h: Track all our VM ranges. We will use this information
+        for malloc introspection.
+
+        (bmalloc::VMHeap::allocateSmallPage):
+        (bmalloc::VMHeap::allocateMediumPage):
+        (bmalloc::VMHeap::allocateLargeRange): Updated for renames.
+
 2015-02-18  Zan Dobersek  <zdobersek@igalia.com>
 
         Build bmalloc through CMake as a static library. It's then linked either
index 663211d..72606b7 100644 (file)
@@ -15,6 +15,7 @@
                140FA00519CE4B6800FFD3C8 /* LineMetadata.h in Headers */ = {isa = PBXBuildFile; fileRef = 140FA00419CE4B6800FFD3C8 /* LineMetadata.h */; settings = {ATTRIBUTES = (Private, ); }; };
                143CB81C19022BC900B16A45 /* StaticMutex.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 143CB81A19022BC900B16A45 /* StaticMutex.cpp */; };
                143CB81D19022BC900B16A45 /* StaticMutex.h in Headers */ = {isa = PBXBuildFile; fileRef = 143CB81B19022BC900B16A45 /* StaticMutex.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               1440AFC91A95142400837FAA /* SuperChunk.h in Headers */ = {isa = PBXBuildFile; fileRef = 1440AFC81A95142400837FAA /* SuperChunk.h */; settings = {ATTRIBUTES = (Private, ); }; };
                1448C30018F3754600502839 /* mbmalloc.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1448C2FF18F3754300502839 /* mbmalloc.cpp */; };
                1448C30118F3754C00502839 /* bmalloc.h in Headers */ = {isa = PBXBuildFile; fileRef = 1448C2FE18F3754300502839 /* bmalloc.h */; settings = {ATTRIBUTES = (Private, ); }; };
                14895D911A3A319C0006235D /* Environment.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14895D8F1A3A319C0006235D /* Environment.cpp */; };
@@ -90,6 +91,7 @@
                143CB81B19022BC900B16A45 /* StaticMutex.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = StaticMutex.h; path = bmalloc/StaticMutex.h; sourceTree = "<group>"; };
                143E29E918CAE8BE00FE8A0F /* MediumPage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MediumPage.h; path = bmalloc/MediumPage.h; sourceTree = "<group>"; };
                143E29ED18CAE90500FE8A0F /* SmallPage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SmallPage.h; path = bmalloc/SmallPage.h; sourceTree = "<group>"; };
+               1440AFC81A95142400837FAA /* SuperChunk.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SuperChunk.h; path = bmalloc/SuperChunk.h; sourceTree = "<group>"; };
                144469E417A46BFE00F9EA1D /* Cache.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = Cache.cpp; path = bmalloc/Cache.cpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
                144469E517A46BFE00F9EA1D /* Cache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = Cache.h; path = bmalloc/Cache.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
                144469FD17A61F1F00F9EA1D /* PerThread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = PerThread.h; path = bmalloc/PerThread.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
                                14105E8318E14374003A106E /* ObjectType.cpp */,
                                1485656018A43DBA00ED6942 /* ObjectType.h */,
                                145F6874179DF84100D65598 /* Sizes.h */,
+                               1440AFC81A95142400837FAA /* SuperChunk.h */,
                                144F7BFB18BFC517003537F3 /* VMHeap.cpp */,
                                144F7BFC18BFC517003537F3 /* VMHeap.h */,
                        );
                                14DD789018F48CEB00950702 /* Sizes.h in Headers */,
                                14DD78C718F48D7500950702 /* BAssert.h in Headers */,
                                14DD78D018F48D7500950702 /* VMAllocate.h in Headers */,
+                               1440AFC91A95142400837FAA /* SuperChunk.h in Headers */,
                                14DD78CE18F48D7500950702 /* Syscall.h in Headers */,
                                14DD78C618F48D7500950702 /* AsyncTask.h in Headers */,
                                14DD78BA18F48D6B00950702 /* Page.h in Headers */,
diff --git a/Source/bmalloc/bmalloc/SuperChunk.h b/Source/bmalloc/bmalloc/SuperChunk.h
new file mode 100644 (file)
index 0000000..5f8fa4b
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2015 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#ifndef SuperChunk_h
+#define SuperChunk_h
+
+#include "LargeChunk.h"
+#include "MediumChunk.h"
+#include "SmallChunk.h"
+
+namespace bmalloc {
+
+class SuperChunk {
+public:
+    static SuperChunk* create();
+
+    SmallChunk* smallChunk();
+    MediumChunk* mediumChunk();
+    LargeChunk* largeChunk();
+
+private:
+    SuperChunk();
+};
+
+inline SuperChunk* SuperChunk::create()
+{
+    void* result = static_cast<char*>(vmAllocate(superChunkSize, superChunkSize));
+    return new (result) SuperChunk;
+}
+
+inline SuperChunk::SuperChunk()
+{
+    new (smallChunk()) SmallChunk;
+    new (mediumChunk()) MediumChunk;
+    new (largeChunk()) LargeChunk;
+}
+
+inline SmallChunk* SuperChunk::smallChunk()
+{
+    return reinterpret_cast<SmallChunk*>(
+        reinterpret_cast<char*>(this) + smallChunkOffset);
+}
+
+inline MediumChunk* SuperChunk::mediumChunk()
+{
+    return reinterpret_cast<MediumChunk*>(
+        reinterpret_cast<char*>(this) + mediumChunkOffset);
+}
+
+inline LargeChunk* SuperChunk::largeChunk()
+{
+    return reinterpret_cast<LargeChunk*>(
+        reinterpret_cast<char*>(this) + largeChunkOffset);
+}
+
+} // namespace bmalloc
+
+#endif // SuperChunk_h
index bc7db38..d71449b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2014 Apple Inc. All rights reserved.
+ * Copyright (C) 2014, 2015 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -27,6 +27,7 @@
 #include "LargeChunk.h"
 #include "Line.h"
 #include "PerProcess.h"
+#include "SuperChunk.h"
 #include "VMHeap.h"
 #include <thread>
 
@@ -36,19 +37,20 @@ VMHeap::VMHeap()
 {
 }
 
-void VMHeap::allocateSuperChunk()
+void VMHeap::grow()
 {
-    char* superChunk = static_cast<char*>(vmAllocate(superChunkSize, superChunkSize));
+    SuperChunk* superChunk = SuperChunk::create();
+    m_superChunks.push(superChunk);
 
-    SmallChunk* smallChunk = new (superChunk + smallChunkOffset) SmallChunk;
+    SmallChunk* smallChunk = superChunk->smallChunk();
     for (auto* it = smallChunk->begin(); it != smallChunk->end(); ++it)
         m_smallPages.push(it);
 
-    MediumChunk* mediumChunk = new (superChunk + mediumChunkOffset) MediumChunk;
+    MediumChunk* mediumChunk = superChunk->mediumChunk();
     for (auto* it = mediumChunk->begin(); it != mediumChunk->end(); ++it)
         m_mediumPages.push(it);
 
-    LargeChunk* largeChunk = new (superChunk + largeChunkOffset) LargeChunk;
+    LargeChunk* largeChunk = superChunk->largeChunk();
     m_largeRanges.insert(BoundaryTag::init(largeChunk));
 }
 
index 1d90e1c..b34ba78 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2014 Apple Inc. All rights reserved.
+ * Copyright (C) 2014, 2015 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -40,6 +40,7 @@ namespace bmalloc {
 class BeginTag;
 class EndTag;
 class Heap;
+class SuperChunk;
 
 class VMHeap {
 public:
@@ -55,17 +56,18 @@ public:
     void deallocateLargeRange(std::unique_lock<StaticMutex>&, Range);
 
 private:
-    void allocateSuperChunk();
+    void grow();
 
     Vector<SmallPage*> m_smallPages;
     Vector<MediumPage*> m_mediumPages;
     SegregatedFreeList m_largeRanges;
+    Vector<SuperChunk*> m_superChunks;
 };
 
 inline SmallPage* VMHeap::allocateSmallPage()
 {
     if (!m_smallPages.size())
-        allocateSuperChunk();
+        grow();
 
     return m_smallPages.pop();
 }
@@ -73,7 +75,7 @@ inline SmallPage* VMHeap::allocateSmallPage()
 inline MediumPage* VMHeap::allocateMediumPage()
 {
     if (!m_mediumPages.size())
-        allocateSuperChunk();
+        grow();
 
     return m_mediumPages.pop();
 }
@@ -82,7 +84,7 @@ inline Range VMHeap::allocateLargeRange(size_t size)
 {
     Range range = m_largeRanges.take(size);
     if (!range) {
-        allocateSuperChunk();
+        grow();
         range = m_largeRanges.take(size);
         BASSERT(range);
     }
@@ -93,7 +95,7 @@ inline Range VMHeap::allocateLargeRange(size_t alignment, size_t size, size_t un
 {
     Range range = m_largeRanges.take(alignment, size, unalignedSize);
     if (!range) {
-        allocateSuperChunk();
+        grow();
         range = m_largeRanges.take(alignment, size, unalignedSize);
         BASSERT(range);
     }