Title: [217918] trunk/Source/bmalloc
Revision
217918
Author
[email protected]
Date
2017-06-07 21:05:43 -0700 (Wed, 07 Jun 2017)

Log Message

bmalloc: memory APIs don't need to be heap members
https://bugs.webkit.org/show_bug.cgi?id=173076

Reviewed by Sam Weinig.

Asking the OS about memory use is unrelated to the state of bmalloc's
heap, so it's a better separation of concerns if related code is not 
part of the heap.

* bmalloc/AvailableMemory.cpp:
(bmalloc::memoryStatus):
* bmalloc/AvailableMemory.h:
(bmalloc::MemoryStatus::MemoryStatus):
(bmalloc::isUnderMemoryPressure):
(bmalloc::memoryFootprint):
(bmalloc::percentAvailableMemoryInUse):
* bmalloc/Heap.cpp:
(bmalloc::Heap::Heap):
(bmalloc::Heap::updateMemoryInUseParameters): Deleted.
* bmalloc/Heap.h:
(bmalloc::Heap::isUnderMemoryPressure): Deleted.
(bmalloc::Heap::memoryFootprint): Deleted.
(bmalloc::Heap::percentAvailableMemoryInUse): Deleted.

Modified Paths

Diff

Modified: trunk/Source/bmalloc/ChangeLog (217917 => 217918)


--- trunk/Source/bmalloc/ChangeLog	2017-06-08 03:32:21 UTC (rev 217917)
+++ trunk/Source/bmalloc/ChangeLog	2017-06-08 04:05:43 UTC (rev 217918)
@@ -1,3 +1,29 @@
+2017-06-07  Geoffrey Garen  <[email protected]>
+
+        bmalloc: memory APIs don't need to be heap members
+        https://bugs.webkit.org/show_bug.cgi?id=173076
+
+        Reviewed by Sam Weinig.
+
+        Asking the OS about memory use is unrelated to the state of bmalloc's
+        heap, so it's a better separation of concerns if related code is not 
+        part of the heap.
+
+        * bmalloc/AvailableMemory.cpp:
+        (bmalloc::memoryStatus):
+        * bmalloc/AvailableMemory.h:
+        (bmalloc::MemoryStatus::MemoryStatus):
+        (bmalloc::isUnderMemoryPressure):
+        (bmalloc::memoryFootprint):
+        (bmalloc::percentAvailableMemoryInUse):
+        * bmalloc/Heap.cpp:
+        (bmalloc::Heap::Heap):
+        (bmalloc::Heap::updateMemoryInUseParameters): Deleted.
+        * bmalloc/Heap.h:
+        (bmalloc::Heap::isUnderMemoryPressure): Deleted.
+        (bmalloc::Heap::memoryFootprint): Deleted.
+        (bmalloc::Heap::percentAvailableMemoryInUse): Deleted.
+
 2017-06-06  Yusuke Suzuki  <[email protected]>
 
         struct does not accept initializer-form if member has initializers in GCC 4.9

Modified: trunk/Source/bmalloc/bmalloc/AvailableMemory.cpp (217917 => 217918)


--- trunk/Source/bmalloc/bmalloc/AvailableMemory.cpp	2017-06-08 03:32:21 UTC (rev 217917)
+++ trunk/Source/bmalloc/bmalloc/AvailableMemory.cpp	2017-06-08 04:05:43 UTC (rev 217918)
@@ -92,4 +92,21 @@
     return availableMemory;
 }
 
+#if BPLATFORM(IOS)
+MemoryStatus memoryStatus()
+{
+    task_vm_info_data_t vmInfo;
+    mach_msg_type_number_t vmSize = TASK_VM_INFO_COUNT;
+    
+    size_t memoryFootprint = 0;
+    if (KERN_SUCCESS == task_info(mach_task_self(), TASK_VM_INFO, (task_info_t)(&vmInfo), &vmSize))
+        memoryFootprint = static_cast<size_t>(vmInfo.phys_footprint);
+
+    double percentInUse = static_cast<double>(memoryFootprint) / static_cast<double>(availableMemory());
+    double percentAvailableMemoryInUse = std::min(percentInUse, 1.0);
+    
+    return MemoryStatus(memoryFootprint, percentAvailableMemoryInUse);
+}
+#endif
+
 } // namespace bmalloc

Modified: trunk/Source/bmalloc/bmalloc/AvailableMemory.h (217917 => 217918)


--- trunk/Source/bmalloc/bmalloc/AvailableMemory.h	2017-06-08 03:32:21 UTC (rev 217917)
+++ trunk/Source/bmalloc/bmalloc/AvailableMemory.h	2017-06-08 04:05:43 UTC (rev 217918)
@@ -32,5 +32,40 @@
 
 size_t availableMemory();
 
+#if BPLATFORM(IOS)
+struct MemoryStatus {
+    MemoryStatus(size_t memoryFootprint, double percentAvailableMemoryInUse)
+        : memoryFootprint(memoryFootprint)
+        , percentAvailableMemoryInUse(percentAvailableMemoryInUse)
+    {
+    }
+
+    size_t memoryFootprint;
+    double percentAvailableMemoryInUse;
+};
+
+MemoryStatus memoryStatus();
+
+inline size_t memoryFootprint()
+{
+    auto memoryUse = memoryStatus();
+    return memoryUse.memoryFootprint;
 }
 
+inline double percentAvailableMemoryInUse()
+{
+    auto memoryUse = memoryStatus();
+    return memoryUse.percentAvailableMemoryInUse;
+}
+#endif
+
+inline bool isUnderMemoryPressure()
+{
+#if BPLATFORM(IOS)
+    return percentAvailableMemoryInUse() > memoryPressureThreshold;
+#else
+    return false;
+#endif
+}
+    
+} // namespace bmalloc

Modified: trunk/Source/bmalloc/bmalloc/Heap.cpp (217917 => 217918)


--- trunk/Source/bmalloc/bmalloc/Heap.cpp	2017-06-08 03:32:21 UTC (rev 217917)
+++ trunk/Source/bmalloc/bmalloc/Heap.cpp	2017-06-08 04:05:43 UTC (rev 217918)
@@ -25,9 +25,7 @@
 
 #include "Heap.h"
 
-#if BPLATFORM(IOS)
 #include "AvailableMemory.h"
-#endif
 #include "BumpAllocator.h"
 #include "Chunk.h"
 #include "DebugHeap.h"
@@ -36,15 +34,6 @@
 #include "SmallPage.h"
 #include <thread>
 
-#if BOS(DARWIN)
-#include "bmalloc.h"
-#if BPLATFORM(IOS)
-#import <mach/host_info.h>
-#import <mach/mach.h>
-#import <mach/mach_error.h>
-#endif
-#endif
-
 namespace bmalloc {
 
 Heap::Heap(std::lock_guard<StaticMutex>&)
@@ -51,9 +40,6 @@
     : m_vmPageSizePhysical(vmPageSizePhysical())
     , m_scavenger(*this, &Heap::concurrentScavenge)
     , m_debugHeap(nullptr)
-#if BPLATFORM(IOS)
-    , m_maxAvailableMemory(availableMemory())
-#endif
 {
     RELEASE_BASSERT(vmPageSizePhysical() >= smallPageSize);
     RELEASE_BASSERT(vmPageSize() >= vmPageSizePhysical());
@@ -132,22 +118,6 @@
         m_pageClasses[i] = (computePageSize(i) - 1) / smallPageSize;
 }
 
-#if BPLATFORM(IOS)
-void Heap::updateMemoryInUseParameters()
-{
-    task_vm_info_data_t vmInfo;
-    mach_msg_type_number_t vmSize = TASK_VM_INFO_COUNT;
-    
-    if (KERN_SUCCESS != task_info(mach_task_self(), TASK_VM_INFO, (task_info_t)(&vmInfo), &vmSize))
-        m_memoryFootprint = 0;
-    else
-        m_memoryFootprint = static_cast<size_t>(vmInfo.phys_footprint);
-
-    double percentInUse = static_cast<double>(m_memoryFootprint) / static_cast<double>(m_maxAvailableMemory);
-    m_percentAvailableMemoryInUse = std::min(percentInUse, 1.0);
-}
-#endif
-
 void Heap::concurrentScavenge()
 {
     std::lock_guard<StaticMutex> lock(PerProcess<Heap>::mutex());

Modified: trunk/Source/bmalloc/bmalloc/Heap.h (217917 => 217918)


--- trunk/Source/bmalloc/bmalloc/Heap.h	2017-06-08 03:32:21 UTC (rev 217917)
+++ trunk/Source/bmalloc/bmalloc/Heap.h	2017-06-08 04:05:43 UTC (rev 217918)
@@ -72,10 +72,6 @@
 
     void scavenge(std::lock_guard<StaticMutex>&);
 
-    size_t memoryFootprint();
-    double percentAvailableMemoryInUse();
-    bool isUnderMemoryPressure();
-    
 #if BOS(DARWIN)
     void setScavengerThreadQOSClass(qos_class_t overrideClass) { m_requestedScavengerThreadQOSClass = overrideClass; }
 #endif
@@ -116,10 +112,6 @@
     
     void concurrentScavenge();
     
-#if BPLATFORM(IOS)
-    void updateMemoryInUseParameters();
-#endif
-
     size_t m_vmPageSizePhysical;
     Vector<LineMetadata> m_smallLineMetadata;
     std::array<size_t, sizeClassCount> m_pageClasses;
@@ -141,12 +133,6 @@
     Environment m_environment;
     DebugHeap* m_debugHeap;
 
-#if BPLATFORM(IOS)
-    size_t m_maxAvailableMemory;
-    size_t m_memoryFootprint;
-    double m_percentAvailableMemoryInUse;
-#endif
-
     VMHeap m_vmHeap;
 
 #if BOS(DARWIN)
@@ -171,31 +157,6 @@
     deallocateSmallLine(lock, object);
 }
 
-inline bool Heap::isUnderMemoryPressure()
-{
-#if BPLATFORM(IOS)
-    return percentAvailableMemoryInUse() > memoryPressureThreshold;
-#else
-    return false;
-#endif
-}
-    
-#if BPLATFORM(IOS)
-inline size_t Heap::memoryFootprint()
-{
-    updateMemoryInUseParameters();
-
-    return m_memoryFootprint;
-}
-
-inline double Heap::percentAvailableMemoryInUse()
-{
-    updateMemoryInUseParameters();
-
-    return m_percentAvailableMemoryInUse;
-}
-#endif
-
 } // namespace bmalloc
 
 #endif // Heap_h

Modified: trunk/Source/bmalloc/bmalloc/bmalloc.h (217917 => 217918)


--- trunk/Source/bmalloc/bmalloc/bmalloc.h	2017-06-08 03:32:21 UTC (rev 217917)
+++ trunk/Source/bmalloc/bmalloc/bmalloc.h	2017-06-08 04:05:43 UTC (rev 217918)
@@ -94,12 +94,12 @@
 #if BPLATFORM(IOS)
 inline size_t memoryFootprint()
 {
-    return PerProcess<Heap>::get()->memoryFootprint();
+    return bmalloc::memoryFootprint();
 }
 
 inline double percentAvailableMemoryInUse()
 {
-    return PerProcess<Heap>::get()->percentAvailableMemoryInUse();
+    return bmalloc::percentAvailableMemoryInUse();
 }
 #endif
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to