<!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" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { 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 #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#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>
<title>[20747] branches/js-collector-tweaks/JavaScriptCore</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/20747">20747</a></dd>
<dt>Author</dt> <dd>mjs</dd>
<dt>Date</dt> <dd>2007-04-06 01:26:13 -0700 (Fri, 06 Apr 2007)</dd>
</dl>

<h3>Log Message</h3>
<pre>        Not reviewed, experimental change.
        
        - change blocks to 64k in size, and use various platform-specific calls to allocate at 64k-aligned addresses

        * kjs/collector.cpp:
        (KJS::allocateBlock):
        (KJS::freeBlock):
        (KJS::Collector::allocate):
        (KJS::Collector::collect):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branchesjscollectortweaksJavaScriptCoreChangeLog">branches/js-collector-tweaks/JavaScriptCore/ChangeLog</a></li>
<li><a href="#branchesjscollectortweaksJavaScriptCorekjscollectorcpp">branches/js-collector-tweaks/JavaScriptCore/kjs/collector.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchesjscollectortweaksJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/js-collector-tweaks/JavaScriptCore/ChangeLog (20746 => 20747)</h4>
<pre class="diff"><span>
<span class="info">--- branches/js-collector-tweaks/JavaScriptCore/ChangeLog        2007-04-06 06:45:53 UTC (rev 20746)
+++ branches/js-collector-tweaks/JavaScriptCore/ChangeLog        2007-04-06 08:26:13 UTC (rev 20747)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2007-04-06  Maciej Stachowiak  &lt;mjs@apple.com&gt;
+
+        Not reviewed, experimental change.
+        
+        - change blocks to 64k in size, and use various platform-specific calls to allocate at 64k-aligned addresses
+
+        * kjs/collector.cpp:
+        (KJS::allocateBlock):
+        (KJS::freeBlock):
+        (KJS::Collector::allocate):
+        (KJS::Collector::collect):
+
</ins><span class="cx"> 2007-04-05  Maciej Stachowiak  &lt;mjs@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Not reviewed, experimental change.
</span></span></pre></div>
<a id="branchesjscollectortweaksJavaScriptCorekjscollectorcpp"></a>
<div class="modfile"><h4>Modified: branches/js-collector-tweaks/JavaScriptCore/kjs/collector.cpp (20746 => 20747)</h4>
<pre class="diff"><span>
<span class="info">--- branches/js-collector-tweaks/JavaScriptCore/kjs/collector.cpp        2007-04-06 06:45:53 UTC (rev 20746)
+++ branches/js-collector-tweaks/JavaScriptCore/kjs/collector.cpp        2007-04-06 08:26:13 UTC (rev 20747)
</span><span class="lines">@@ -37,8 +37,10 @@
</span><span class="cx"> #if PLATFORM(DARWIN)
</span><span class="cx"> 
</span><span class="cx"> #include &lt;mach/mach_port.h&gt;
</span><ins>+#include &lt;mach/mach_init.h&gt;
</ins><span class="cx"> #include &lt;mach/task.h&gt;
</span><span class="cx"> #include &lt;mach/thread_act.h&gt;
</span><ins>+#include &lt;mach/vm_map.h&gt;
</ins><span class="cx"> 
</span><span class="cx"> #elif PLATFORM(WIN_OS)
</span><span class="cx"> 
</span><span class="lines">@@ -46,6 +48,9 @@
</span><span class="cx"> 
</span><span class="cx"> #elif PLATFORM(UNIX)
</span><span class="cx"> 
</span><ins>+#include &lt;stdlib.h&gt;
+#include &lt;sys/mman.h&gt;
+
</ins><span class="cx"> #if HAVE(PTHREAD_NP_H)
</span><span class="cx"> #include &lt;pthread_np.h&gt;
</span><span class="cx"> #endif
</span><span class="lines">@@ -59,14 +64,13 @@
</span><span class="cx"> namespace KJS {
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-
</del><span class="cx"> // tunable parameters
</span><span class="cx"> 
</span><span class="cx"> template&lt;bool is32Bit, bool is64Bit&gt; struct CellSize;
</span><span class="cx"> template&lt;&gt; struct CellSize&lt;true, false&gt; { static const size_t m_value = 48; }; // 32-bit
</span><span class="cx"> template&lt;&gt; struct CellSize&lt;false, true&gt; { static const size_t m_value = 80; }; // 64-bit
</span><span class="cx"> 
</span><del>-const size_t BLOCK_SIZE = (8 * 4096);
</del><ins>+const size_t BLOCK_SIZE = (16 * 4096); // 64k
</ins><span class="cx"> const size_t SPARE_EMPTY_BLOCKS = 2;
</span><span class="cx"> const size_t MIN_ARRAY_SIZE = 14;
</span><span class="cx"> const size_t GROWTH_FACTOR = 2;
</span><span class="lines">@@ -74,6 +78,8 @@
</span><span class="cx"> const size_t ALLOCATIONS_PER_COLLECTION = 1000;
</span><span class="cx"> 
</span><span class="cx"> // derived constants
</span><ins>+const size_t PTR_IN_BLOCK_MASK = (BLOCK_SIZE - 1);
+const size_t BLOCK_MASK = (~PTR_IN_BLOCK_MASK);
</ins><span class="cx"> const size_t MINIMUM_CELL_SIZE = CellSize&lt;sizeof(void*) == sizeof(uint32_t), sizeof(void*) == sizeof(uint64_t)&gt;::m_value;
</span><span class="cx"> const size_t CELL_ARRAY_LENGTH = (MINIMUM_CELL_SIZE / sizeof(double)) + (MINIMUM_CELL_SIZE % sizeof(double) != 0 ? 1 : 0);
</span><span class="cx"> const size_t CELL_SIZE = CELL_ARRAY_LENGTH * sizeof(double);
</span><span class="lines">@@ -134,6 +140,58 @@
</span><span class="cx"> bool GCLock::isLocked = false;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+static CollectorBlock* allocateBlock()
+{
+#if PLATFORM(DARWIN)    
+    vm_address_t ptr = 0;
+    vm_map(current_task(), &amp;ptr, BLOCK_SIZE, PTR_IN_BLOCK_MASK, VM_FLAGS_ANYWHERE, MEMORY_OBJECT_NULL, 0, FALSE, VM_PROT_DEFAULT, VM_PROT_DEFAULT, VM_INHERIT_DEFAULT);
+#elif PLATFORM(WIN)
+     // windows virtual address granularity is naturally 64k
+    LPVOID ptr = VirtualAlloc(NULL lpAddress, BLOCK_SIZE, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
+#elif HAVE(POSIX_MEMALIGN)
+    void* ptr;
+    posix_memalign(ptr, BLOCK_SIZE, BLOCK_SIZE);
+#else
+    static size_t pagesize = getpagesize();
+    
+    size_t extra = 0;
+    if (BLOCK_SIZE &gt; pagesize) {
+        extra = BLOCK_SIZE - pagesize;
+    }
+
+    void* result = mmap(NULL, BLOCK_SIZE + extra, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
+
+    uintptr_t ptr = reinterpret_cast&lt;uintptr_t&gt;(result);
+    size_t adjust = 0;
+    if ((ptr &amp; PTR_IN_BLOCK_MASK) != 0)
+        adjust = BLOCK_SIZE - (ptr &amp; PTR_IN_BLOCK_MASK);
+
+    if (adjust &gt; 0)
+        munmap(reinterpret_cast&lt;void*&gt;(ptr), adjust);
+
+    if (adjust &lt; extra)
+        munmap(reinterpret_cast&lt;void*&gt;(ptr + adjust + BLOCK_SIZE), extra - adjust);
+
+    ptr += adjust;
+    memset(reinterpret_cast&lt;void*&gt;(ptr), 0, BLOCK_SIZE);
+#endif
+
+    return reinterpret_cast&lt;CollectorBlock*&gt;(ptr);
+}
+
+static void freeBlock(CollectorBlock* block)
+{
+#if PLATFORM(DARWIN)    
+    vm_deallocate(current_task(), reinterpret_cast&lt;vm_address_t&gt;(block), BLOCK_SIZE);
+#elif PLATFORM(WIN)
+    VirtualFree(block, BLOCK_SIZE, MEM_RELEASE);
+#elif HAVE(POSIX_MEMALIGN)
+    free(block);
+#else
+    munmap(block, BLOCK_SIZE);
+#endif
+}
+
</ins><span class="cx"> void* Collector::allocate(size_t s)
</span><span class="cx"> {
</span><span class="cx">   ASSERT(JSLock::lockCount() &gt; 0);
</span><span class="lines">@@ -183,7 +241,7 @@
</span><span class="cx">       heap.blocks = static_cast&lt;CollectorBlock **&gt;(fastRealloc(heap.blocks, numBlocks * sizeof(CollectorBlock *)));
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    targetBlock = static_cast&lt;CollectorBlock *&gt;(fastCalloc(1, sizeof(CollectorBlock)));
</del><ins>+    targetBlock = allocateBlock();
</ins><span class="cx">     targetBlock-&gt;freeList = targetBlock-&gt;cells;
</span><span class="cx">     targetBlockUsedCells = 0;
</span><span class="cx">     heap.blocks[usedBlocks] = targetBlock;
</span><span class="lines">@@ -788,7 +846,7 @@
</span><span class="cx">       emptyBlocks++;
</span><span class="cx">       if (emptyBlocks &gt; SPARE_EMPTY_BLOCKS) {
</span><span class="cx"> #if !DEBUG_COLLECTOR
</span><del>-        fastFree(curBlock);
</del><ins>+        freeBlock(curBlock);
</ins><span class="cx"> #endif
</span><span class="cx">         // swap with the last block so we compact as we go
</span><span class="cx">         heap.blocks[block] = heap.blocks[heap.usedBlocks - 1];
</span></span></pre>
</div>
</div>

</body>
</html>