<!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 <mjs@apple.com>
+
+ 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 <mjs@apple.com>
</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 <mach/mach_port.h>
</span><ins>+#include <mach/mach_init.h>
</ins><span class="cx"> #include <mach/task.h>
</span><span class="cx"> #include <mach/thread_act.h>
</span><ins>+#include <mach/vm_map.h>
</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 <stdlib.h>
+#include <sys/mman.h>
+
</ins><span class="cx"> #if HAVE(PTHREAD_NP_H)
</span><span class="cx"> #include <pthread_np.h>
</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<bool is32Bit, bool is64Bit> struct CellSize;
</span><span class="cx"> template<> struct CellSize<true, false> { static const size_t m_value = 48; }; // 32-bit
</span><span class="cx"> template<> struct CellSize<false, true> { 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<sizeof(void*) == sizeof(uint32_t), sizeof(void*) == sizeof(uint64_t)>::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(), &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 > 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<uintptr_t>(result);
+ size_t adjust = 0;
+ if ((ptr & PTR_IN_BLOCK_MASK) != 0)
+ adjust = BLOCK_SIZE - (ptr & PTR_IN_BLOCK_MASK);
+
+ if (adjust > 0)
+ munmap(reinterpret_cast<void*>(ptr), adjust);
+
+ if (adjust < extra)
+ munmap(reinterpret_cast<void*>(ptr + adjust + BLOCK_SIZE), extra - adjust);
+
+ ptr += adjust;
+ memset(reinterpret_cast<void*>(ptr), 0, BLOCK_SIZE);
+#endif
+
+ return reinterpret_cast<CollectorBlock*>(ptr);
+}
+
+static void freeBlock(CollectorBlock* block)
+{
+#if PLATFORM(DARWIN)
+ vm_deallocate(current_task(), reinterpret_cast<vm_address_t>(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() > 0);
</span><span class="lines">@@ -183,7 +241,7 @@
</span><span class="cx"> heap.blocks = static_cast<CollectorBlock **>(fastRealloc(heap.blocks, numBlocks * sizeof(CollectorBlock *)));
</span><span class="cx"> }
</span><span class="cx">
</span><del>- targetBlock = static_cast<CollectorBlock *>(fastCalloc(1, sizeof(CollectorBlock)));
</del><ins>+ targetBlock = allocateBlock();
</ins><span class="cx"> targetBlock->freeList = targetBlock->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 > 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>