<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[183181] trunk/Source</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/183181">183181</a></dd>
<dt>Author</dt> <dd>akling@apple.com</dd>
<dt>Date</dt> <dd>2015-04-23 01:22:13 -0700 (Thu, 23 Apr 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>There should only be one way to get the system memory size.
&lt;https://webkit.org/b/144081&gt;

Reviewed by Antti Koivisto.

Source/WebKit/mac:

* Misc/WebKitSystemBits.h:
* Misc/WebKitSystemBits.m:
(WebMemorySize): Deleted.
* WebView/WebView.mm:
(+[WebView _setCacheModel:]):
(roundUpToPowerOf2): Deleted.

Source/WebKit/win:

* WebView.cpp:
(WebView::setCacheModel):

Source/WebKit2:

* NetworkProcess/cocoa/NetworkProcessCocoa.mm:
(WebKit::NetworkProcess::platformSetCacheModel):
(WebKit::memorySize): Deleted.
* WebProcess/cocoa/WebProcessCocoa.mm:
(WebKit::WebProcess::platformSetCacheModel):
(WebKit::memorySize): Deleted.

Source/WTF:

Merge all the logic from other RAM size fetcher helpers into WTF's.

Darwin ports now use host_info() instead of sysctl(), since that was the more common way
of doing this.

Also bumped the fallback answer from 128 MB to 512 MB to bring it closer to today's hardware.

Finally, the number is rounded up to the next multiple of 128 MB, to avoid misunderstandings
on some systems where the number returned by the kernel is slightly lower than the marketing
number. Removed the &quot;fudging&quot; that was used in some places, since this fixes that cleanly.

* wtf/RAMSize.cpp:
(WTF::computeRAMSize):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWTFChangeLog">trunk/Source/WTF/ChangeLog</a></li>
<li><a href="#trunkSourceWTFwtfRAMSizecpp">trunk/Source/WTF/wtf/RAMSize.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformaudioiosMediaSessionManagerIOSmm">trunk/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm</a></li>
<li><a href="#trunkSourceWebCoreplatformiosLegacyTileCachemm">trunk/Source/WebCore/platform/ios/LegacyTileCache.mm</a></li>
<li><a href="#trunkSourceWebCoreplatformiosSystemMemoryh">trunk/Source/WebCore/platform/ios/SystemMemory.h</a></li>
<li><a href="#trunkSourceWebCoreplatformiosSystemMemoryIOScpp">trunk/Source/WebCore/platform/ios/SystemMemoryIOS.cpp</a></li>
<li><a href="#trunkSourceWebKitmacChangeLog">trunk/Source/WebKit/mac/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitmacMiscWebKitSystemBitsh">trunk/Source/WebKit/mac/Misc/WebKitSystemBits.h</a></li>
<li><a href="#trunkSourceWebKitmacMiscWebKitSystemBitsm">trunk/Source/WebKit/mac/Misc/WebKitSystemBits.m</a></li>
<li><a href="#trunkSourceWebKitmacWebViewWebViewmm">trunk/Source/WebKit/mac/WebView/WebView.mm</a></li>
<li><a href="#trunkSourceWebKitwinChangeLog">trunk/Source/WebKit/win/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitwinWebViewcpp">trunk/Source/WebKit/win/WebView.cpp</a></li>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2NetworkProcesscocoaNetworkProcessCocoamm">trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkProcessCocoa.mm</a></li>
<li><a href="#trunkSourceWebKit2WebProcesscocoaWebProcessCocoamm">trunk/Source/WebKit2/WebProcess/cocoa/WebProcessCocoa.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWTFChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/ChangeLog (183180 => 183181)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/ChangeLog        2015-04-23 08:15:04 UTC (rev 183180)
+++ trunk/Source/WTF/ChangeLog        2015-04-23 08:22:13 UTC (rev 183181)
</span><span class="lines">@@ -1,3 +1,24 @@
</span><ins>+2015-04-23  Andreas Kling  &lt;akling@apple.com&gt;
+
+        There should only be one way to get the system memory size.
+        &lt;https://webkit.org/b/144081&gt;
+
+        Reviewed by Antti Koivisto.
+
+        Merge all the logic from other RAM size fetcher helpers into WTF's.
+
+        Darwin ports now use host_info() instead of sysctl(), since that was the more common way
+        of doing this.
+
+        Also bumped the fallback answer from 128 MB to 512 MB to bring it closer to today's hardware.
+
+        Finally, the number is rounded up to the next multiple of 128 MB, to avoid misunderstandings
+        on some systems where the number returned by the kernel is slightly lower than the marketing
+        number. Removed the &quot;fudging&quot; that was used in some places, since this fixes that cleanly.
+
+        * wtf/RAMSize.cpp:
+        (WTF::computeRAMSize):
+
</ins><span class="cx"> 2015-04-22  Darin Adler  &lt;darin@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Eliminate remaining uses of OwnPtr and PassOwnPtr in WebCore outside the editing and platform directories
</span></span></pre></div>
<a id="trunkSourceWTFwtfRAMSizecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/RAMSize.cpp (183180 => 183181)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/RAMSize.cpp        2015-04-23 08:15:04 UTC (rev 183180)
+++ trunk/Source/WTF/wtf/RAMSize.cpp        2015-04-23 08:22:13 UTC (rev 183181)
</span><span class="lines">@@ -27,10 +27,14 @@
</span><span class="cx"> #include &quot;RAMSize.h&quot;
</span><span class="cx"> 
</span><span class="cx"> #include &quot;StdLibExtras.h&quot;
</span><ins>+#include &lt;mutex&gt;
+
</ins><span class="cx"> #if OS(DARWIN)
</span><del>-#include &lt;sys/param.h&gt;
-#include &lt;sys/types.h&gt;
-#include &lt;sys/sysctl.h&gt;
</del><ins>+#import &lt;dispatch/dispatch.h&gt;
+#import &lt;mach/host_info.h&gt;
+#import &lt;mach/mach.h&gt;
+#import &lt;mach/mach_error.h&gt;
+#import &lt;math.h&gt;
</ins><span class="cx"> #elif OS(UNIX)
</span><span class="cx"> #include &lt;unistd.h&gt;
</span><span class="cx"> #elif OS(WINDOWS)
</span><span class="lines">@@ -39,22 +43,34 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WTF {
</span><span class="cx"> 
</span><del>-static const size_t ramSizeGuess = 128 * MB;
</del><ins>+static const size_t ramSizeGuess = 512 * MB;
</ins><span class="cx"> 
</span><span class="cx"> static size_t computeRAMSize()
</span><span class="cx"> {
</span><del>-#if OS(DARWIN)
-    int mib[2];
-    uint64_t ramSize;
-    size_t length;
</del><ins>+#if PLATFORM(IOS_SIMULATOR)
+    // Pretend we have 512MB of memory to make cache sizes behave like on device.
+    return ramSizeGuess;
+#elif OS(DARWIN)
+    host_basic_info_data_t hostInfo;
</ins><span class="cx"> 
</span><del>-    mib[0] = CTL_HW;
-    mib[1] = HW_MEMSIZE;
-    length = sizeof(int64_t);
-    int sysctlResult = sysctl(mib, 2, &amp;ramSize, &amp;length, 0, 0);
-    if (sysctlResult == -1)
</del><ins>+    mach_port_t host = mach_host_self();
+    mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT;
+    kern_return_t r = host_info(host, HOST_BASIC_INFO, (host_info_t)&amp;hostInfo, &amp;count);
+    mach_port_deallocate(mach_task_self(), host);
+    if (r != KERN_SUCCESS) {
+        LOG_ERROR(&quot;%s : host_info(%d) : %s.\n&quot;, __FUNCTION__, r, mach_error_string(r));
</ins><span class="cx">         return ramSizeGuess;
</span><del>-    return ramSize &gt; std::numeric_limits&lt;size_t&gt;::max() ? std::numeric_limits&lt;size_t&gt;::max() : static_cast&lt;size_t&gt;(ramSize);
</del><ins>+    }
+
+    if (hostInfo.max_mem &gt; std::numeric_limits&lt;size_t&gt;::max())
+        return std::numeric_limits&lt;size_t&gt;::max();
+
+    size_t sizeAccordingToKernel = static_cast&lt;size_t&gt;(hostInfo.max_mem);
+    size_t multiple = 128 * MB;
+
+    // Round up the memory size to a multiple of 128MB because max_mem may not be exactly 512MB
+    // (for example) and we have code that depends on those boundaries.
+    return ((sizeAccordingToKernel + multiple - 1) / multiple) * multiple;
</ins><span class="cx"> #elif OS(UNIX)
</span><span class="cx">     long pages = sysconf(_SC_PHYS_PAGES);
</span><span class="cx">     long pageSize = sysconf(_SC_PAGE_SIZE);
</span><span class="lines">@@ -73,7 +89,11 @@
</span><span class="cx"> 
</span><span class="cx"> size_t ramSize()
</span><span class="cx"> {
</span><del>-    static const size_t ramSize = computeRAMSize();
</del><ins>+    static size_t ramSize;
+    static std::once_flag onceFlag;
+    std::call_once(onceFlag, [] {
+        ramSize = computeRAMSize();
+    });
</ins><span class="cx">     return ramSize;
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformaudioiosMediaSessionManagerIOSmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm (183180 => 183181)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm        2015-04-23 08:15:04 UTC (rev 183180)
+++ trunk/Source/WebCore/platform/audio/ios/MediaSessionManagerIOS.mm        2015-04-23 08:22:13 UTC (rev 183181)
</span><span class="lines">@@ -42,6 +42,7 @@
</span><span class="cx"> #import &lt;MediaPlayer/MPVolumeView.h&gt;
</span><span class="cx"> #import &lt;UIKit/UIApplication.h&gt;
</span><span class="cx"> #import &lt;objc/runtime.h&gt;
</span><ins>+#import &lt;wtf/RAMSize.h&gt;
</ins><span class="cx"> #import &lt;wtf/RetainPtr.h&gt;
</span><span class="cx"> 
</span><span class="cx"> SOFT_LINK_FRAMEWORK(AVFoundation)
</span><span class="lines">@@ -139,8 +140,8 @@
</span><span class="cx">     if (deviceClass == wkDeviceClassiPhone || deviceClass == wkDeviceClassiPod)
</span><span class="cx">         addRestriction(MediaSession::Video, InlineVideoPlaybackRestricted);
</span><span class="cx"> 
</span><del>-    if (systemTotalMemory() &lt; systemMemoryRequiredForVideoInBackgroundTabs) {
-        LOG(Media, &quot;MediaSessionManageriOS::resetRestrictions - restricting video in background tabs because system memory = %zul&quot;, systemTotalMemory());
</del><ins>+    if (ramSize() &lt; systemMemoryRequiredForVideoInBackgroundTabs) {
+        LOG(Media, &quot;MediaSessionManageriOS::resetRestrictions - restricting video in background tabs because system memory = %zul&quot;, ramSize());
</ins><span class="cx">         addRestriction(MediaSession::Video, BackgroundTabPlaybackRestricted);
</span><span class="cx">     }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformiosLegacyTileCachemm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/ios/LegacyTileCache.mm (183180 => 183181)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/ios/LegacyTileCache.mm        2015-04-23 08:15:04 UTC (rev 183180)
+++ trunk/Source/WebCore/platform/ios/LegacyTileCache.mm        2015-04-23 08:22:13 UTC (rev 183181)
</span><span class="lines">@@ -42,6 +42,7 @@
</span><span class="cx"> #include &quot;WebCoreSystemInterface.h&quot;
</span><span class="cx"> #include &quot;WebCoreThreadRun.h&quot;
</span><span class="cx"> #include &lt;wtf/CurrentTime.h&gt;
</span><ins>+#include &lt;wtf/RAMSize.h&gt;
</ins><span class="cx"> 
</span><span class="cx"> @interface WAKView (WebViewExtras)
</span><span class="cx"> - (void)_dispatchTileDidDraw:(CALayer*)tile;
</span><span class="lines">@@ -436,8 +437,7 @@
</span><span class="cx"> {
</span><span class="cx">     static unsigned capacity;
</span><span class="cx">     if (!capacity) {
</span><del>-        size_t totalMemory = systemTotalMemory();
-        totalMemory /= 1024 * 1024;
</del><ins>+        size_t totalMemory = ramSize() / 1024 / 1024;
</ins><span class="cx">         if (totalMemory &gt;= 1024)
</span><span class="cx">             capacity = 128 * 1024 * 1024;
</span><span class="cx">         else if (totalMemory &gt;= 512)
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformiosSystemMemoryh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/ios/SystemMemory.h (183180 => 183181)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/ios/SystemMemory.h        2015-04-23 08:15:04 UTC (rev 183180)
+++ trunk/Source/WebCore/platform/ios/SystemMemory.h        2015-04-23 08:22:13 UTC (rev 183181)
</span><span class="lines">@@ -33,7 +33,6 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> WEBCORE_EXPORT int systemMemoryLevel(); // In [0, 100]
</span><del>-WEBCORE_EXPORT size_t systemTotalMemory();
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformiosSystemMemoryIOScpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/ios/SystemMemoryIOS.cpp (183180 => 183181)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/ios/SystemMemoryIOS.cpp        2015-04-23 08:15:04 UTC (rev 183180)
+++ trunk/Source/WebCore/platform/ios/SystemMemoryIOS.cpp        2015-04-23 08:22:13 UTC (rev 183181)
</span><span class="lines">@@ -29,7 +29,6 @@
</span><span class="cx"> #include &quot;config.h&quot;
</span><span class="cx"> #include &quot;SystemMemory.h&quot;
</span><span class="cx"> 
</span><del>-#include &lt;mach/mach.h&gt;
</del><span class="cx"> #include &lt;sys/sysctl.h&gt;
</span><span class="cx"> #include &lt;wtf/Assertions.h&gt;
</span><span class="cx"> #include &lt;wtf/CurrentTime.h&gt;
</span><span class="lines">@@ -53,35 +52,4 @@
</span><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-#if !PLATFORM(IOS_SIMULATOR)
-static host_basic_info_data_t gHostBasicInfo;
-
-static void initCapabilities(void)
-{
-    // Discover our CPU type
-    mach_port_t host = mach_host_self();
-    mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT;
-    kern_return_t returnValue = host_info(host, HOST_BASIC_INFO, reinterpret_cast&lt;host_info_t&gt;(&amp;gHostBasicInfo), &amp;count);
-    mach_port_deallocate(mach_task_self(), host);
-    if (returnValue != KERN_SUCCESS)
-        LOG_ERROR(&quot;%s : host_info(%d) : %s.\n&quot;, __FUNCTION__, returnValue, mach_error_string(returnValue));
-}
-#endif
-
-size_t systemTotalMemory()
-{
-#if PLATFORM(IOS_SIMULATOR)
-    return 512 * 1024 * 1024;
-#else
-    // FIXME: Consider using C++11 thread primitives.
-    static pthread_once_t initControl = PTHREAD_ONCE_INIT;
-
-    pthread_once(&amp;initControl, initCapabilities);
-    // The value in gHostBasicInfo.max_mem is often lower than the amount we're
-    // interested in (e.g., does this device have at least 256MB of RAM?)
-    // Round the value to the nearest power of 2.
-    return static_cast&lt;size_t&gt;(exp2(ceil(log2(gHostBasicInfo.max_mem))));
-#endif
-}
-
</del><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebKitmacChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/ChangeLog (183180 => 183181)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/mac/ChangeLog        2015-04-23 08:15:04 UTC (rev 183180)
+++ trunk/Source/WebKit/mac/ChangeLog        2015-04-23 08:22:13 UTC (rev 183181)
</span><span class="lines">@@ -1,3 +1,17 @@
</span><ins>+2015-04-23  Andreas Kling  &lt;akling@apple.com&gt;
+
+        There should only be one way to get the system memory size.
+        &lt;https://webkit.org/b/144081&gt;
+
+        Reviewed by Antti Koivisto.
+
+        * Misc/WebKitSystemBits.h:
+        * Misc/WebKitSystemBits.m:
+        (WebMemorySize): Deleted.
+        * WebView/WebView.mm:
+        (+[WebView _setCacheModel:]):
+        (roundUpToPowerOf2): Deleted.
+
</ins><span class="cx"> 2015-04-22  Darin Adler  &lt;darin@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Remove OwnPtr and PassOwnPtr use from WebKit/cf, WebKit/mac, and WebKit2
</span></span></pre></div>
<a id="trunkSourceWebKitmacMiscWebKitSystemBitsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/Misc/WebKitSystemBits.h (183180 => 183181)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/mac/Misc/WebKitSystemBits.h        2015-04-23 08:15:04 UTC (rev 183180)
+++ trunk/Source/WebKit/mac/Misc/WebKitSystemBits.h        2015-04-23 08:22:13 UTC (rev 183181)
</span><span class="lines">@@ -32,7 +32,6 @@
</span><span class="cx"> extern &quot;C&quot; {
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-uint64_t WebMemorySize(void);
</del><span class="cx"> unsigned long long WebVolumeFreeSize(NSString *path);
</span><span class="cx"> int WebNumberOfCPUs(void);
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKitmacMiscWebKitSystemBitsm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/Misc/WebKitSystemBits.m (183180 => 183181)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/mac/Misc/WebKitSystemBits.m        2015-04-23 08:15:04 UTC (rev 183180)
+++ trunk/Source/WebKit/mac/Misc/WebKitSystemBits.m        2015-04-23 08:22:13 UTC (rev 183181)
</span><span class="lines">@@ -36,46 +36,6 @@
</span><span class="cx"> #import &lt;sys/types.h&gt;
</span><span class="cx"> #import &lt;wtf/Assertions.h&gt;
</span><span class="cx"> 
</span><del>-#if !PLATFORM(IOS_SIMULATOR)
-
-static host_basic_info_data_t gHostBasicInfo;
-static pthread_once_t initControl = PTHREAD_ONCE_INIT;
-
-static void initCapabilities(void)
-{
-    mach_msg_type_number_t  count;
-    kern_return_t r;
-    mach_port_t host;
-
-    /* Discover our CPU type */
-    host = mach_host_self();
-    count = HOST_BASIC_INFO_COUNT;
-    r = host_info(host, HOST_BASIC_INFO, (host_info_t) &amp;gHostBasicInfo, &amp;count);
-    mach_port_deallocate(mach_task_self(), host);
-    if (r != KERN_SUCCESS) {
-        LOG_ERROR(&quot;%s : host_info(%d) : %s.\n&quot;, __FUNCTION__, r, mach_error_string(r));
-    }
-}
-
-#endif
-
-uint64_t WebMemorySize(void)
-{
-#if PLATFORM(IOS_SIMULATOR)
-    // Pretend we have 512MB of memory to make cache sizes behave like on device
-    return 512 * 1024 * 1024;
-#else
-    pthread_once(&amp;initControl, initCapabilities);
-#if PLATFORM(IOS)
-    // On iOS, round up the memory size to a power of 2 because max_mem may not be exactly 256MB
-    // (for example) and we have code that depends on those boundaries.
-    return powf(2.0, ceilf(log2f(gHostBasicInfo.max_mem)));
-#else
-    return gHostBasicInfo.max_mem;
-#endif
-#endif
-}
-
</del><span class="cx"> int WebNumberOfCPUs(void)
</span><span class="cx"> {
</span><span class="cx">     static int numCPUs = 0;
</span></span></pre></div>
<a id="trunkSourceWebKitmacWebViewWebViewmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/WebView/WebView.mm (183180 => 183181)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/mac/WebView/WebView.mm        2015-04-23 08:15:04 UTC (rev 183180)
+++ trunk/Source/WebKit/mac/WebView/WebView.mm        2015-04-23 08:22:13 UTC (rev 183181)
</span><span class="lines">@@ -204,6 +204,7 @@
</span><span class="cx"> #import &lt;wtf/HashTraits.h&gt;
</span><span class="cx"> #import &lt;wtf/MainThread.h&gt;
</span><span class="cx"> #import &lt;wtf/ObjcRuntimeExtras.h&gt;
</span><ins>+#import &lt;wtf/RAMSize.h&gt;
</ins><span class="cx"> #import &lt;wtf/RefCountedLeakCounter.h&gt;
</span><span class="cx"> #import &lt;wtf/RefPtr.h&gt;
</span><span class="cx"> #import &lt;wtf/RunLoop.h&gt;
</span><span class="lines">@@ -7718,11 +7719,6 @@
</span><span class="cx"> }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-static inline uint64_t roundUpToPowerOf2(uint64_t num)
-{
-    return powf(2.0, ceilf(log2f(num)));
-}
-
</del><span class="cx"> + (void)_setCacheModel:(WebCacheModel)cacheModel
</span><span class="cx"> {
</span><span class="cx">     if (s_didSetCacheModel &amp;&amp; cacheModel == s_cacheModel)
</span><span class="lines">@@ -7732,7 +7728,7 @@
</span><span class="cx">     if (!nsurlCacheDirectory)
</span><span class="cx">         nsurlCacheDirectory = NSHomeDirectory();
</span><span class="cx"> 
</span><del>-    static uint64_t memSize = roundUpToPowerOf2(WebMemorySize() / 1024 / 1024);
</del><ins>+    static uint64_t memSize = ramSize() / 1024 / 1024;
</ins><span class="cx">     unsigned long long diskFreeSize = WebVolumeFreeSize(nsurlCacheDirectory) / 1024 / 1000;
</span><span class="cx">     NSURLCache *nsurlCache = [NSURLCache sharedURLCache];
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKitwinChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/win/ChangeLog (183180 => 183181)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/win/ChangeLog        2015-04-23 08:15:04 UTC (rev 183180)
+++ trunk/Source/WebKit/win/ChangeLog        2015-04-23 08:22:13 UTC (rev 183181)
</span><span class="lines">@@ -1,3 +1,13 @@
</span><ins>+2015-04-23  Andreas Kling  &lt;akling@apple.com&gt;
+
+        There should only be one way to get the system memory size.
+        &lt;https://webkit.org/b/144081&gt;
+
+        Reviewed by Antti Koivisto.
+
+        * WebView.cpp:
+        (WebView::setCacheModel):
+
</ins><span class="cx"> 2015-04-13  Jer Noble  &lt;jer.noble@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [Fullscreen] ChromeClient::exitVideoFullscreen() should take a pointer to a HTMLVideoElement.
</span></span></pre></div>
<a id="trunkSourceWebKitwinWebViewcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/win/WebView.cpp (183180 => 183181)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/win/WebView.cpp        2015-04-23 08:15:04 UTC (rev 183180)
+++ trunk/Source/WebKit/win/WebView.cpp        2015-04-23 08:22:13 UTC (rev 183181)
</span><span class="lines">@@ -155,6 +155,7 @@
</span><span class="cx"> #include &lt;WebCore/WindowsTouch.h&gt;
</span><span class="cx"> #include &lt;bindings/ScriptValue.h&gt;
</span><span class="cx"> #include &lt;wtf/MainThread.h&gt;
</span><ins>+#include &lt;wtf/RAMSize.h&gt;
</ins><span class="cx"> 
</span><span class="cx"> #if USE(CG)
</span><span class="cx"> #include &lt;CoreGraphics/CGContext.h&gt;
</span><span class="lines">@@ -521,9 +522,10 @@
</span><span class="cx">     long cacheDiskCapacity = 0;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+    unsigned long long memSize = ramSize() / 1024 / 1024;
+
</ins><span class="cx">     // As a fudge factor, use 1000 instead of 1024, in case the reported byte 
</span><span class="cx">     // count doesn't align exactly to a megabyte boundary.
</span><del>-    unsigned long long memSize = WebMemorySize() / 1024 / 1000;
</del><span class="cx">     unsigned long long diskFreeSize = WebVolumeFreeSize(cacheDirectory) / 1024 / 1000;
</span><span class="cx"> 
</span><span class="cx">     unsigned cacheTotalCapacity = 0;
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (183180 => 183181)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2015-04-23 08:15:04 UTC (rev 183180)
+++ trunk/Source/WebKit2/ChangeLog        2015-04-23 08:22:13 UTC (rev 183181)
</span><span class="lines">@@ -1,3 +1,17 @@
</span><ins>+2015-04-23  Andreas Kling  &lt;akling@apple.com&gt;
+
+        There should only be one way to get the system memory size.
+        &lt;https://webkit.org/b/144081&gt;
+
+        Reviewed by Antti Koivisto.
+
+        * NetworkProcess/cocoa/NetworkProcessCocoa.mm:
+        (WebKit::NetworkProcess::platformSetCacheModel):
+        (WebKit::memorySize): Deleted.
+        * WebProcess/cocoa/WebProcessCocoa.mm:
+        (WebKit::WebProcess::platformSetCacheModel):
+        (WebKit::memorySize): Deleted.
+
</ins><span class="cx"> 2015-04-23  Chris Dumez  &lt;cdumez@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [WK2] WebDiagnosticLoggingClient is leaking
</span></span></pre></div>
<a id="trunkSourceWebKit2NetworkProcesscocoaNetworkProcessCocoamm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkProcessCocoa.mm (183180 => 183181)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkProcessCocoa.mm        2015-04-23 08:15:04 UTC (rev 183180)
+++ trunk/Source/WebKit2/NetworkProcess/cocoa/NetworkProcessCocoa.mm        2015-04-23 08:22:13 UTC (rev 183181)
</span><span class="lines">@@ -33,9 +33,7 @@
</span><span class="cx"> #import &quot;NetworkResourceLoader.h&quot;
</span><span class="cx"> #import &quot;SandboxExtension.h&quot;
</span><span class="cx"> #import &lt;WebCore/CFNetworkSPI.h&gt;
</span><del>-#import &lt;mach/host_info.h&gt;
-#import &lt;mach/mach.h&gt;
-#import &lt;mach/mach_error.h&gt;
</del><ins>+#import &lt;wtf/RAMSize.h&gt;
</ins><span class="cx"> 
</span><span class="cx"> namespace WebKit {
</span><span class="cx"> 
</span><span class="lines">@@ -94,24 +92,6 @@
</span><span class="cx">     _CFURLCacheSetMinSizeForVMCachedResource(cache.get(), NetworkResourceLoader::fileBackedResourceMinimumSize());
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static uint64_t memorySize()
-{
-    static host_basic_info_data_t hostInfo;
-
-    static dispatch_once_t once;
-    dispatch_once(&amp;once, ^() {
-        mach_port_t host = mach_host_self();
-        mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT;
-        kern_return_t r = host_info(host, HOST_BASIC_INFO, (host_info_t)&amp;hostInfo, &amp;count);
-        mach_port_deallocate(mach_task_self(), host);
-
-        if (r != KERN_SUCCESS)
-            LOG_ERROR(&quot;%s : host_info(%d) : %s.\n&quot;, __FUNCTION__, r, mach_error_string(r));
-    });
-
-    return hostInfo.max_mem;
-}
-
</del><span class="cx"> static uint64_t volumeFreeSize(const String&amp; path)
</span><span class="cx"> {
</span><span class="cx">     NSDictionary *fileSystemAttributesDictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:(NSString *)path error:NULL];
</span><span class="lines">@@ -120,9 +100,10 @@
</span><span class="cx"> 
</span><span class="cx"> void NetworkProcess::platformSetCacheModel(CacheModel cacheModel)
</span><span class="cx"> {
</span><ins>+    uint64_t memSize = ramSize() / 1024 / 1024;
+
</ins><span class="cx">     // As a fudge factor, use 1000 instead of 1024, in case the reported byte
</span><span class="cx">     // count doesn't align exactly to a megabyte boundary.
</span><del>-    uint64_t memSize = memorySize() / 1024 / 1000;
</del><span class="cx">     uint64_t diskFreeSize = volumeFreeSize(m_diskCacheDirectory) / 1024 / 1000;
</span><span class="cx"> 
</span><span class="cx">     unsigned cacheTotalCapacity = 0;
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcesscocoaWebProcessCocoamm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/cocoa/WebProcessCocoa.mm (183180 => 183181)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/cocoa/WebProcessCocoa.mm        2015-04-23 08:15:04 UTC (rev 183180)
+++ trunk/Source/WebKit2/WebProcess/cocoa/WebProcessCocoa.mm        2015-04-23 08:22:13 UTC (rev 183181)
</span><span class="lines">@@ -53,11 +53,9 @@
</span><span class="cx"> #import &lt;WebKitSystemInterface.h&gt;
</span><span class="cx"> #import &lt;algorithm&gt;
</span><span class="cx"> #import &lt;dispatch/dispatch.h&gt;
</span><del>-#import &lt;mach/host_info.h&gt;
-#import &lt;mach/mach.h&gt;
-#import &lt;mach/mach_error.h&gt;
</del><span class="cx"> #import &lt;objc/runtime.h&gt;
</span><span class="cx"> #import &lt;stdio.h&gt;
</span><ins>+#import &lt;wtf/RamSize.h&gt;
</ins><span class="cx"> 
</span><span class="cx"> #define ENABLE_MANUAL_WEBPROCESS_SANDBOXING !PLATFORM(IOS)
</span><span class="cx"> 
</span><span class="lines">@@ -65,24 +63,6 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebKit {
</span><span class="cx"> 
</span><del>-static uint64_t memorySize()
-{
-    static host_basic_info_data_t hostInfo;
-
-    static dispatch_once_t once;
-    dispatch_once(&amp;once, ^() {
-        mach_port_t host = mach_host_self();
-        mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT;
-        kern_return_t r = host_info(host, HOST_BASIC_INFO, (host_info_t)&amp;hostInfo, &amp;count);
-        mach_port_deallocate(mach_task_self(), host);
-
-        if (r != KERN_SUCCESS)
-            LOG_ERROR(&quot;%s : host_info(%d) : %s.\n&quot;, __FUNCTION__, r, mach_error_string(r));
-    });
-
-    return hostInfo.max_mem;
-}
-
</del><span class="cx"> static uint64_t volumeFreeSize(NSString *path)
</span><span class="cx"> {
</span><span class="cx">     NSDictionary *fileSystemAttributesDictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:path error:NULL];
</span><span class="lines">@@ -95,9 +75,10 @@
</span><span class="cx">     if (!nsurlCacheDirectory)
</span><span class="cx">         nsurlCacheDirectory = NSHomeDirectory();
</span><span class="cx"> 
</span><ins>+    uint64_t memSize = ramSize() / 1024 / 1024;
+
</ins><span class="cx">     // As a fudge factor, use 1000 instead of 1024, in case the reported byte 
</span><span class="cx">     // count doesn't align exactly to a megabyte boundary.
</span><del>-    uint64_t memSize = memorySize() / 1024 / 1000;
</del><span class="cx">     uint64_t diskFreeSize = volumeFreeSize(nsurlCacheDirectory.get()) / 1024 / 1000;
</span><span class="cx"> 
</span><span class="cx">     unsigned cacheTotalCapacity = 0;
</span></span></pre>
</div>
</div>

</body>
</html>