[bmalloc] VMHeap can be merge into Heap
authorbasuke.suzuki@sony.com <basuke.suzuki@sony.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 8 Feb 2020 10:35:40 +0000 (10:35 +0000)
committerbasuke.suzuki@sony.com <basuke.suzuki@sony.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 8 Feb 2020 10:35:40 +0000 (10:35 +0000)
https://bugs.webkit.org/show_bug.cgi?id=207410

Reviewed by Yusuke Suzuki.

VMHeap has only one member function in it and Heap is the only client of that.
No member variable is defined. It does nothing special with its context as a class.
It is safe to merge the function into Heap.

* CMakeLists.txt:
* bmalloc.xcodeproj/project.pbxproj:
* bmalloc/Heap.cpp:
(bmalloc::Heap::allocateLarge):
(bmalloc::Heap::tryAllocateLargeChunk): Moved from VMHeap.
* bmalloc/Heap.h:
* bmalloc/VMHeap.cpp: Removed.
* bmalloc/VMHeap.h: Removed.

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

Source/bmalloc/CMakeLists.txt
Source/bmalloc/ChangeLog
Source/bmalloc/bmalloc.xcodeproj/project.pbxproj
Source/bmalloc/bmalloc/Heap.cpp
Source/bmalloc/bmalloc/Heap.h
Source/bmalloc/bmalloc/VMHeap.cpp [deleted file]
Source/bmalloc/bmalloc/VMHeap.h [deleted file]

index 0add0ac..5522a84 100644 (file)
@@ -31,7 +31,6 @@ set(bmalloc_SOURCES
     bmalloc/ObjectType.cpp
     bmalloc/PerProcess.cpp
     bmalloc/Scavenger.cpp
-    bmalloc/VMHeap.cpp
     bmalloc/bmalloc.cpp
 )
 
@@ -127,7 +126,6 @@ set(bmalloc_PUBLIC_HEADERS
     bmalloc/StdLibExtras.h
     bmalloc/Syscall.h
     bmalloc/VMAllocate.h
-    bmalloc/VMHeap.h
     bmalloc/Vector.h
     bmalloc/Zone.h
     bmalloc/bmalloc.h
index 690fd6c..485fdfd 100644 (file)
@@ -1,3 +1,23 @@
+2020-02-08  Basuke Suzuki  <basuke.suzuki@sony.com>
+
+        [bmalloc] VMHeap can be merge into Heap
+        https://bugs.webkit.org/show_bug.cgi?id=207410
+
+        Reviewed by Yusuke Suzuki.
+
+        VMHeap has only one member function in it and Heap is the only client of that.
+        No member variable is defined. It does nothing special with its context as a class.
+        It is safe to merge the function into Heap.
+
+        * CMakeLists.txt:
+        * bmalloc.xcodeproj/project.pbxproj:
+        * bmalloc/Heap.cpp:
+        (bmalloc::Heap::allocateLarge):
+        (bmalloc::Heap::tryAllocateLargeChunk): Moved from VMHeap.
+        * bmalloc/Heap.h:
+        * bmalloc/VMHeap.cpp: Removed.
+        * bmalloc/VMHeap.h: Removed.
+
 2020-02-05  Don Olmstead  <don.olmstead@sony.com>
 
         [bmalloc] Add declspec support for export macros
index 3b85e77..dfb12de 100644 (file)
@@ -78,7 +78,6 @@
                0F7EB85A1F955A1100F1ABCB /* DeferredDecommitInlines.h in Headers */ = {isa = PBXBuildFile; fileRef = 0F7EB8591F955A0F00F1ABCB /* DeferredDecommitInlines.h */; settings = {ATTRIBUTES = (Private, ); }; };
                0FD557331F7EDB7B00B1F0A3 /* HeapKind.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0FD557321F7EDB7B00B1F0A3 /* HeapKind.cpp */; };
                1400274918F89C1300115C97 /* Heap.h in Headers */ = {isa = PBXBuildFile; fileRef = 14DA320C18875B09007269E0 /* Heap.h */; settings = {ATTRIBUTES = (Private, ); }; };
-               1400274A18F89C2300115C97 /* VMHeap.h in Headers */ = {isa = PBXBuildFile; fileRef = 144F7BFC18BFC517003537F3 /* VMHeap.h */; settings = {ATTRIBUTES = (Private, ); }; };
                140FA00319CE429C00FFD3C8 /* BumpRange.h in Headers */ = {isa = PBXBuildFile; fileRef = 140FA00219CE429C00FFD3C8 /* BumpRange.h */; settings = {ATTRIBUTES = (Private, ); }; };
                140FA00519CE4B6800FFD3C8 /* LineMetadata.h in Headers */ = {isa = PBXBuildFile; fileRef = 140FA00419CE4B6800FFD3C8 /* LineMetadata.h */; settings = {ATTRIBUTES = (Private, ); }; };
                141D9B001C8E51C0000ABBA0 /* List.h in Headers */ = {isa = PBXBuildFile; fileRef = 141D9AFF1C8E51C0000ABBA0 /* List.h */; settings = {ATTRIBUTES = (Private, ); }; };
                14F271C518EA397E008C152F /* Deallocator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 145F6859179DC90200D65598 /* Deallocator.cpp */; };
                14F271C718EA3990008C152F /* Heap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14DA320E18875D9F007269E0 /* Heap.cpp */; };
                14F271C818EA3990008C152F /* ObjectType.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14105E8318E14374003A106E /* ObjectType.cpp */; };
-               14F271C918EA3990008C152F /* VMHeap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 144F7BFB18BFC517003537F3 /* VMHeap.cpp */; };
                4426E2801C838EE0008EB042 /* Logging.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4426E27E1C838EE0008EB042 /* Logging.cpp */; };
                4426E2811C838EE0008EB042 /* Logging.h in Headers */ = {isa = PBXBuildFile; fileRef = 4426E27F1C838EE0008EB042 /* Logging.h */; settings = {ATTRIBUTES = (Private, ); }; };
                4426E2831C839547008EB042 /* BSoftLinking.h in Headers */ = {isa = PBXBuildFile; fileRef = 4426E2821C839547008EB042 /* BSoftLinking.h */; };
                144BE11E1CA346520099C8C0 /* Object.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Object.h; path = bmalloc/Object.h; sourceTree = "<group>"; };
                144C07F21C7B70260051BB6A /* LargeMap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = LargeMap.cpp; path = bmalloc/LargeMap.cpp; sourceTree = "<group>"; };
                144C07F31C7B70260051BB6A /* LargeMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = LargeMap.h; path = bmalloc/LargeMap.h; sourceTree = "<group>"; };
-               144F7BFB18BFC517003537F3 /* VMHeap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = VMHeap.cpp; path = bmalloc/VMHeap.cpp; sourceTree = "<group>"; };
-               144F7BFC18BFC517003537F3 /* VMHeap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VMHeap.h; path = bmalloc/VMHeap.h; sourceTree = "<group>"; };
                1452478618BC757C00F80098 /* SmallLine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SmallLine.h; path = bmalloc/SmallLine.h; sourceTree = "<group>"; };
                145F6855179DC8CA00D65598 /* Allocator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = Allocator.cpp; path = bmalloc/Allocator.cpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
                145F6856179DC8CA00D65598 /* Allocator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = Allocator.h; path = bmalloc/Allocator.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
                                0F5BF1501F22E1570029D91D /* Scavenger.cpp */,
                                0F5BF1511F22E1570029D91D /* Scavenger.h */,
                                145F6874179DF84100D65598 /* Sizes.h */,
-                               144F7BFB18BFC517003537F3 /* VMHeap.cpp */,
-                               144F7BFC18BFC517003537F3 /* VMHeap.h */,
                                1440AFCC1A9527AF00837FAA /* Zone.cpp */,
                                1440AFCA1A95261100837FAA /* Zone.h */,
                        );
                                14DD78CE18F48D7500950702 /* Syscall.h in Headers */,
                                14DD78CF18F48D7500950702 /* Vector.h in Headers */,
                                14DD78D018F48D7500950702 /* VMAllocate.h in Headers */,
-                               1400274A18F89C2300115C97 /* VMHeap.h in Headers */,
                                1440AFCB1A95261100837FAA /* Zone.h in Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                                0F26A7A5205483130090A141 /* PerProcess.cpp in Sources */,
                                AD14AD2A202529C700890E3B /* ProcessCheck.mm in Sources */,
                                0F5BF1521F22E1570029D91D /* Scavenger.cpp in Sources */,
-                               14F271C918EA3990008C152F /* VMHeap.cpp in Sources */,
                                1440AFCD1A9527AF00837FAA /* Zone.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
index 6d714f0..f2a3e9a 100644 (file)
 #include "Scavenger.h"
 #include "SmallLine.h"
 #include "SmallPage.h"
-#include "VMHeap.h"
 #include "bmalloc.h"
 #include <thread>
 #include <vector>
 
+#if BOS(DARWIN)
+#include "Zone.h"
+#endif
+
 namespace bmalloc {
 
 Heap::Heap(HeapKind kind, LockHolder&)
@@ -574,7 +577,7 @@ void* Heap::allocateLarge(UniqueLockHolder& lock, size_t alignment, size_t size,
 
         ASSERT_OR_RETURN_ON_FAILURE(!usingGigacage());
 
-        range = VMHeap::get()->tryAllocateLargeChunk(alignment, size);
+        range = tryAllocateLargeChunk(alignment, size);
         ASSERT_OR_RETURN_ON_FAILURE(range);
         
         m_largeFree.add(range);
@@ -593,6 +596,31 @@ void* Heap::allocateLarge(UniqueLockHolder& lock, size_t alignment, size_t size,
 #undef ASSERT_OR_RETURN_ON_FAILURE
 }
 
+LargeRange Heap::tryAllocateLargeChunk(size_t alignment, size_t size)
+{
+    // We allocate VM in aligned multiples to increase the chances that
+    // the OS will provide contiguous ranges that we can merge.
+    size_t roundedAlignment = roundUpToMultipleOf<chunkSize>(alignment);
+    if (roundedAlignment < alignment) // Check for overflow
+        return LargeRange();
+    alignment = roundedAlignment;
+
+    size_t roundedSize = roundUpToMultipleOf<chunkSize>(size);
+    if (roundedSize < size) // Check for overflow
+        return LargeRange();
+    size = roundedSize;
+
+    void* memory = tryVMAllocate(alignment, size);
+    if (!memory)
+        return LargeRange();
+    
+#if BOS(DARWIN)
+    PerProcess<Zone>::get()->addRange(Range(memory, size));
+#endif
+
+    return LargeRange(memory, size, 0, 0);
+}
+
 bool Heap::isLarge(UniqueLockHolder&, void* object)
 {
     return m_objectTypes.get(Object(object).chunk()) == ObjectType::Large;
index 26d7743..a29a3d2 100644 (file)
 
 namespace bmalloc {
 
-class BeginTag;
 class BulkDecommit;
 class BumpAllocator;
 class DebugHeap;
-class EndTag;
 class HeapConstants;
 class Scavenger;
 
@@ -121,10 +119,7 @@ private:
     void allocateSmallChunk(UniqueLockHolder&, size_t pageClass, FailureAction);
     void deallocateSmallChunk(Chunk*, size_t pageClass);
 
-    void mergeLarge(BeginTag*&, EndTag*&, Range&);
-    void mergeLargeLeft(EndTag*&, BeginTag*&, Range&, bool& inVMHeap);
-    void mergeLargeRight(EndTag*&, BeginTag*&, Range&, bool& inVMHeap);
-
+    LargeRange tryAllocateLargeChunk(size_t alignment, size_t);
     LargeRange splitAndAllocate(UniqueLockHolder&, LargeRange&, size_t alignment, size_t);
 
     HeapKind m_kind;
diff --git a/Source/bmalloc/bmalloc/VMHeap.cpp b/Source/bmalloc/bmalloc/VMHeap.cpp
deleted file mode 100644 (file)
index df605ff..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright (C) 2014-2017 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. 
- */
-
-#include "PerProcess.h"
-#include "VMHeap.h"
-#include <thread>
-
-namespace bmalloc {
-
-DEFINE_STATIC_PER_PROCESS_STORAGE(VMHeap);
-
-VMHeap::VMHeap(const LockHolder&)
-{
-}
-
-LargeRange VMHeap::tryAllocateLargeChunk(size_t alignment, size_t size)
-{
-    // We allocate VM in aligned multiples to increase the chances that
-    // the OS will provide contiguous ranges that we can merge.
-    size_t roundedAlignment = roundUpToMultipleOf<chunkSize>(alignment);
-    if (roundedAlignment < alignment) // Check for overflow
-        return LargeRange();
-    alignment = roundedAlignment;
-
-    size_t roundedSize = roundUpToMultipleOf<chunkSize>(size);
-    if (roundedSize < size) // Check for overflow
-        return LargeRange();
-    size = roundedSize;
-
-    void* memory = tryVMAllocate(alignment, size);
-    if (!memory)
-        return LargeRange();
-    
-    Chunk* chunk = static_cast<Chunk*>(memory);
-    
-#if BOS(DARWIN)
-    PerProcess<Zone>::get()->addRange(Range(chunk->bytes(), size));
-#endif
-
-    return LargeRange(chunk->bytes(), size, 0, 0);
-}
-
-} // namespace bmalloc
diff --git a/Source/bmalloc/bmalloc/VMHeap.h b/Source/bmalloc/bmalloc/VMHeap.h
deleted file mode 100644 (file)
index 11f10e3..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (C) 2014-2017 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 VMHeap_h
-#define VMHeap_h
-
-#include "Chunk.h"
-#include "FixedVector.h"
-#include "HeapKind.h"
-#include "LargeRange.h"
-#include "Map.h"
-#include "StaticPerProcess.h"
-#include "Vector.h"
-#if BOS(DARWIN)
-#include "Zone.h"
-#endif
-
-namespace bmalloc {
-
-class BeginTag;
-class EndTag;
-class Heap;
-
-typedef enum { Sync, Async } ScavengeMode;
-
-class VMHeap : public StaticPerProcess<VMHeap> {
-public:
-    VMHeap(const LockHolder&);
-    
-    LargeRange tryAllocateLargeChunk(size_t alignment, size_t);
-};
-DECLARE_STATIC_PER_PROCESS_STORAGE(VMHeap);
-
-} // namespace bmalloc
-
-#endif // VMHeap_h