Title: [122462] trunk/Source
Revision
122462
Author
allan.jen...@nokia.com
Date
2012-07-12 08:34:35 -0700 (Thu, 12 Jul 2012)

Log Message

[Qt] Implement MemoryUsageSupport
https://bugs.webkit.org/show_bug.cgi?id=91094

Reviewed by Adam Barth.

Source/_javascript_Core:

Compile in MemoryStatistics so we can make use of the interface.

* Target.pri:

Source/WebCore:

Implements Qt versions of the memory-usage functions using the information we have available
from the various memory systems used in WebKit.

Also gets rid of a redundant indirection in V8GCController.

* Target.pri:
* bindings/v8/V8GCController.cpp:
(WebCore::V8GCController::gcEpilogue):
(WebCore::V8GCController::checkMemoryUsage):
* platform/qt/MemoryUsageSupportQt.cpp: Added.
(WebCore::mallocMemoryUsage):
(WebCore::memoryUsageKB):
(WebCore::actualMemoryUsageKB):
(WebCore::MemoryUsageSupport::memoryUsageMB):
(WebCore::MemoryUsageSupport::actualMemoryUsageMB):
(WebCore::MemoryUsageSupport::lowMemoryUsageMB):
(WebCore::MemoryUsageSupport::highMemoryUsageMB):
(WebCore::MemoryUsageSupport::highUsageDeltaMB):
(WebCore::MemoryUsageSupport::processMemorySizesInBytes):
* platform/qt/PlatformSupport.h:
(PlatformSupport):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (122461 => 122462)


--- trunk/Source/_javascript_Core/ChangeLog	2012-07-12 15:30:55 UTC (rev 122461)
+++ trunk/Source/_javascript_Core/ChangeLog	2012-07-12 15:34:35 UTC (rev 122462)
@@ -1,3 +1,14 @@
+2012-07-12  Allan Sandfeld Jensen  <allan.jen...@nokia.com>
+
+        [Qt] Implement MemoryUsageSupport
+        https://bugs.webkit.org/show_bug.cgi?id=91094
+
+        Reviewed by Adam Barth.
+
+        Compile in MemoryStatistics so we can make use of the interface.
+
+        * Target.pri:
+
 2012-07-12  Csaba Osztrogonác  <o...@webkit.org>
 
         Remove dead code after r122392.

Modified: trunk/Source/_javascript_Core/Target.pri (122461 => 122462)


--- trunk/Source/_javascript_Core/Target.pri	2012-07-12 15:30:55 UTC (rev 122461)
+++ trunk/Source/_javascript_Core/Target.pri	2012-07-12 15:34:35 UTC (rev 122462)
@@ -218,6 +218,7 @@
     runtime/LiteralParser.cpp \
     runtime/Lookup.cpp \
     runtime/MathObject.cpp \
+    runtime/MemoryStatistics.cpp \
     runtime/NameConstructor.cpp \
     runtime/NameInstance.cpp \
     runtime/NamePrototype.cpp \

Modified: trunk/Source/WebCore/ChangeLog (122461 => 122462)


--- trunk/Source/WebCore/ChangeLog	2012-07-12 15:30:55 UTC (rev 122461)
+++ trunk/Source/WebCore/ChangeLog	2012-07-12 15:34:35 UTC (rev 122462)
@@ -1,3 +1,32 @@
+2012-07-12  Allan Sandfeld Jensen  <allan.jen...@nokia.com>
+
+        [Qt] Implement MemoryUsageSupport
+        https://bugs.webkit.org/show_bug.cgi?id=91094
+
+        Reviewed by Adam Barth.
+
+        Implements Qt versions of the memory-usage functions using the information we have available
+        from the various memory systems used in WebKit.
+
+        Also gets rid of a redundant indirection in V8GCController.
+
+        * Target.pri:
+        * bindings/v8/V8GCController.cpp:
+        (WebCore::V8GCController::gcEpilogue):
+        (WebCore::V8GCController::checkMemoryUsage):
+        * platform/qt/MemoryUsageSupportQt.cpp: Added.
+        (WebCore::mallocMemoryUsage):
+        (WebCore::memoryUsageKB):
+        (WebCore::actualMemoryUsageKB):
+        (WebCore::MemoryUsageSupport::memoryUsageMB):
+        (WebCore::MemoryUsageSupport::actualMemoryUsageMB):
+        (WebCore::MemoryUsageSupport::lowMemoryUsageMB):
+        (WebCore::MemoryUsageSupport::highMemoryUsageMB):
+        (WebCore::MemoryUsageSupport::highUsageDeltaMB):
+        (WebCore::MemoryUsageSupport::processMemorySizesInBytes):
+        * platform/qt/PlatformSupport.h:
+        (PlatformSupport):
+
 2012-07-12  Vsevolod Vlasov  <vse...@chromium.org>
 
         Web Inspector: Revision history view should be updated when uiSourceCodes are removed or replaced.

Modified: trunk/Source/WebCore/Target.pri (122461 => 122462)


--- trunk/Source/WebCore/Target.pri	2012-07-12 15:30:55 UTC (rev 122461)
+++ trunk/Source/WebCore/Target.pri	2012-07-12 15:34:35 UTC (rev 122462)
@@ -1167,7 +1167,7 @@
     platform/LinkHash.cpp \
     platform/Logging.cpp \
     platform/MemoryPressureHandler.cpp \
-    platform/MemoryUsageSupport.cpp \
+    platform/qt/MemoryUsageSupportQt.cpp \
     platform/MIMETypeRegistry.cpp \
     platform/mock/DeviceMotionClientMock.cpp \
     platform/mock/DeviceOrientationClientMock.cpp \

Modified: trunk/Source/WebCore/bindings/v8/V8GCController.cpp (122461 => 122462)


--- trunk/Source/WebCore/bindings/v8/V8GCController.cpp	2012-07-12 15:30:55 UTC (rev 122461)
+++ trunk/Source/WebCore/bindings/v8/V8GCController.cpp	2012-07-12 15:34:35 UTC (rev 122462)
@@ -475,24 +475,7 @@
 
 namespace {
 
-int getMemoryUsageInMB()
-{
-#if PLATFORM(CHROMIUM)
-    return MemoryUsageSupport::memoryUsageMB();
-#else
-    return 0;
-#endif
-}
 
-int getActualMemoryUsageInMB()
-{
-#if PLATFORM(CHROMIUM)
-    return MemoryUsageSupport::actualMemoryUsageMB();
-#else
-    return 0;
-#endif
-}
-
 }  // anonymous namespace
 
 void V8GCController::gcEpilogue()
@@ -506,7 +489,7 @@
     GCEpilogueVisitor<Node, SpecialCaseEpilogueNodeHandler, &DOMDataStore::weakNodeCallback> epilogueNodeVisitor;
     visitActiveDOMNodes(&epilogueNodeVisitor);
 
-    workingSetEstimateMB = getActualMemoryUsageInMB();
+    workingSetEstimateMB = MemoryUsageSupport::actualMemoryUsageMB();
 
 #ifndef NDEBUG
     // Check all survivals are weak.
@@ -530,7 +513,7 @@
     const int lowMemoryUsageMB = MemoryUsageSupport::lowMemoryUsageMB();
     const int highMemoryUsageMB = MemoryUsageSupport::highMemoryUsageMB();
     const int highUsageDeltaMB = MemoryUsageSupport::highUsageDeltaMB();
-    int memoryUsageMB = getMemoryUsageInMB();
+    int memoryUsageMB = MemoryUsageSupport::memoryUsageMB();
     if ((memoryUsageMB > lowMemoryUsageMB && memoryUsageMB > 2 * workingSetEstimateMB) || (memoryUsageMB > highMemoryUsageMB && memoryUsageMB > workingSetEstimateMB + highUsageDeltaMB))
         v8::V8::LowMemoryNotification();
 #endif

Added: trunk/Source/WebCore/platform/qt/MemoryUsageSupportQt.cpp (0 => 122462)


--- trunk/Source/WebCore/platform/qt/MemoryUsageSupportQt.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/qt/MemoryUsageSupportQt.cpp	2012-07-12 15:34:35 UTC (rev 122462)
@@ -0,0 +1,114 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *           (C) 2012 Nokia Corporation and/or its subsidiary(-ies)
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#include "config.h"
+#include "MemoryUsageSupport.h"
+
+#include "JSDOMWindow.h"
+#include <_javascript_Core/MemoryStatistics.h>
+#include <wtf/FastMalloc.h>
+
+#if OS(LINUX)
+#include <malloc.h>
+#endif
+
+namespace WebCore {
+
+#if OS(LINUX)
+static size_t mallocMemoryUsage(bool inuse)
+{
+    // Return how much memory (in bytes) has been allocated on the system heap.
+    struct mallinfo minfo = ::mallinfo();
+
+    // If we want the internal memory usage, we subtract the memory used by
+    // free blocks. That is memory allocated from the system by malloc but
+    // which malloc considers free.
+    return minfo.arena - (inuse ? minfo.fordblks : 0);
+}
+#else
+static size_t mallocMemoryUsage(bool)
+{
+    // FIXME: Implement for other supported OS's.
+    return 0;
+}
+#endif
+
+// This is how much system-memory we use.
+static int memoryUsageKB()
+{
+    size_t mallocUsage = mallocMemoryUsage(false);
+    WTF::FastMallocStatistics fmStats = WTF::fastMallocStatistics();
+
+    // Extract memory statistics from _javascript_Core:
+    JSC::GlobalMemoryStatistics jscStats = JSC::globalMemoryStatistics();
+    size_t jscHeapUsage = JSDOMWindow::commonJSGlobalData()->heap.capacity();
+    return (mallocUsage + fmStats.committedVMBytes + jscStats.stackBytes + jscStats.JITBytes + jscHeapUsage) >> 10;
+}
+
+// This is how much memory we use internally, not including memory only reserved from the system.
+static int actualMemoryUsageKB()
+{
+    size_t mallocUsage = mallocMemoryUsage(true);
+    WTF::FastMallocStatistics fmStats = WTF::fastMallocStatistics();
+
+    // Extract memory statistics from _javascript_Core:
+    JSC::GlobalMemoryStatistics jscStats = JSC::globalMemoryStatistics();
+    size_t jscHeapUsage = JSDOMWindow::commonJSGlobalData()->heap.size();
+    return (mallocUsage + fmStats.committedVMBytes - fmStats.freeListBytes + jscStats.stackBytes + jscStats.JITBytes + jscHeapUsage) >> 10;
+}
+
+int MemoryUsageSupport::memoryUsageMB()
+{
+    return memoryUsageKB() >> 10;
+}
+
+int MemoryUsageSupport::actualMemoryUsageMB()
+{
+    return actualMemoryUsageKB() >> 10;
+}
+
+// FIXME: These values should be determined based on hardware or set by the application.
+
+static const unsigned normalMemoryWatermark = 128; // Chromium default: 256
+static const unsigned highMemoryWatermark = 256; // Chromium default: 1024
+static const unsigned highMemoryDelta = 64; // Chromium default: 128
+
+int MemoryUsageSupport::lowMemoryUsageMB()
+{
+    return normalMemoryWatermark;
+}
+
+int MemoryUsageSupport::highMemoryUsageMB()
+{
+    return highMemoryWatermark;
+}
+
+int MemoryUsageSupport::highUsageDeltaMB()
+{
+    return highMemoryDelta;
+}
+
+bool MemoryUsageSupport::processMemorySizesInBytes(size_t*, size_t*)
+{
+    // FIXME: Not implemented.
+    return false;
+}
+
+} // namespace WebCore

Modified: trunk/Source/WebCore/platform/qt/PlatformSupport.h (122461 => 122462)


--- trunk/Source/WebCore/platform/qt/PlatformSupport.h	2012-07-12 15:30:55 UTC (rev 122461)
+++ trunk/Source/WebCore/platform/qt/PlatformSupport.h	2012-07-12 15:34:35 UTC (rev 122462)
@@ -92,14 +92,6 @@
     // Plugin
     static NPObject* pluginScriptableObject(Widget*);
 
-    // If memory usage is below this threshold, do not bother forcing GC.
-    static int lowMemoryUsageMB() { return 256; }
-
-    // If memory usage is above this threshold, force GC more aggressively.
-    static int highMemoryUsageMB() { return 1024; }
-
-    // Delta of memory usage growth (vs. last actualMemoryUsageMB()) to force GC when memory usage is high.
-    static int highUsageDeltaMB() { return 128; }
 };
 
 }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to