[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc
barraclough at apple.com
barraclough at apple.com
Wed Dec 22 11:45:18 UTC 2010
The following commit has been merged in the debian/experimental branch:
commit 792303e12dcd8bcf574de6bf545e41f0cdd552d6
Author: barraclough at apple.com <barraclough at apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Thu Aug 5 20:57:33 2010 +0000
Bug 43185 - Switch RegisterFile over to use PageAllocation
Reviewed by Sam Weinig.
Remove platform-specific memory allocation code.
* interpreter/RegisterFile.cpp:
(JSC::RegisterFile::~RegisterFile):
(JSC::RegisterFile::releaseExcessCapacity):
* interpreter/RegisterFile.h:
(JSC::RegisterFile::RegisterFile):
(JSC::RegisterFile::grow):
(JSC::RegisterFile::checkAllocatedOkay):
* wtf/PageAllocation.cpp:
(WTF::PageAllocation::lastError):
* wtf/PageAllocation.h:
(WTF::PageAllocation::allocate):
(WTF::PageAllocation::allocateAt):
(WTF::PageAllocation::allocateAligned):
(WTF::PageAllocation::pageSize):
(WTF::PageAllocation::isPageAligned):
(WTF::PageAllocation::isPowerOfTwo):
* wtf/PageReservation.h:
(WTF::PageReservation::commit):
(WTF::PageReservation::decommit):
(WTF::PageReservation::reserve):
(WTF::PageReservation::reserveAt):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@64782 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/JavaScriptCore/ChangeLog b/JavaScriptCore/ChangeLog
index 655e8aa..037a8a4 100644
--- a/JavaScriptCore/ChangeLog
+++ b/JavaScriptCore/ChangeLog
@@ -1,3 +1,33 @@
+2010-08-05 Gavin Barraclough <barraclough at apple.com>
+
+ Reviewed by Sam Weinig.
+
+ Bug 43185 - Switch RegisterFile over to use PageAllocation
+
+ Remove platform-specific memory allocation code.
+
+ * interpreter/RegisterFile.cpp:
+ (JSC::RegisterFile::~RegisterFile):
+ (JSC::RegisterFile::releaseExcessCapacity):
+ * interpreter/RegisterFile.h:
+ (JSC::RegisterFile::RegisterFile):
+ (JSC::RegisterFile::grow):
+ (JSC::RegisterFile::checkAllocatedOkay):
+ * wtf/PageAllocation.cpp:
+ (WTF::PageAllocation::lastError):
+ * wtf/PageAllocation.h:
+ (WTF::PageAllocation::allocate):
+ (WTF::PageAllocation::allocateAt):
+ (WTF::PageAllocation::allocateAligned):
+ (WTF::PageAllocation::pageSize):
+ (WTF::PageAllocation::isPageAligned):
+ (WTF::PageAllocation::isPowerOfTwo):
+ * wtf/PageReservation.h:
+ (WTF::PageReservation::commit):
+ (WTF::PageReservation::decommit):
+ (WTF::PageReservation::reserve):
+ (WTF::PageReservation::reserveAt):
+
2010-08-05 Michael Saboff <msaboff at apple.com>
Reviewed by Darin Adler.
diff --git a/JavaScriptCore/interpreter/RegisterFile.cpp b/JavaScriptCore/interpreter/RegisterFile.cpp
index 63ea5b3..4f5d1d5 100644
--- a/JavaScriptCore/interpreter/RegisterFile.cpp
+++ b/JavaScriptCore/interpreter/RegisterFile.cpp
@@ -35,26 +35,15 @@ namespace JSC {
RegisterFile::~RegisterFile()
{
-#if HAVE(MMAP)
- munmap(m_buffer, ((m_max - m_start) + m_maxGlobals) * sizeof(Register));
-#elif HAVE(VIRTUALALLOC)
-#if OS(WINCE)
- VirtualFree(m_buffer, DWORD(m_commitEnd) - DWORD(m_buffer), MEM_DECOMMIT);
-#endif
- VirtualFree(m_buffer, 0, MEM_RELEASE);
-#else
- fastFree(m_buffer);
-#endif
+ void* base = m_reservation.base();
+ m_reservation.decommit(base, reinterpret_cast<intptr_t>(m_commitEnd) - reinterpret_cast<intptr_t>(base));
+ m_reservation.deallocate();
}
void RegisterFile::releaseExcessCapacity()
{
-#if HAVE(MMAP) && HAVE(MADV_FREE) && !HAVE(VIRTUALALLOC)
- while (madvise(m_start, (m_max - m_start) * sizeof(Register), MADV_FREE) == -1 && errno == EAGAIN) { }
-#elif HAVE(VIRTUALALLOC)
- VirtualFree(m_start, (m_max - m_start) * sizeof(Register), MEM_DECOMMIT);
+ m_reservation.decommit(m_start, reinterpret_cast<intptr_t>(m_commitEnd) - reinterpret_cast<intptr_t>(m_start));
m_commitEnd = m_start;
-#endif
m_maxUsed = m_start;
}
diff --git a/JavaScriptCore/interpreter/RegisterFile.h b/JavaScriptCore/interpreter/RegisterFile.h
index e9b8204..6c4e969 100644
--- a/JavaScriptCore/interpreter/RegisterFile.h
+++ b/JavaScriptCore/interpreter/RegisterFile.h
@@ -35,13 +35,9 @@
#include "WeakGCPtr.h"
#include <stdio.h>
#include <wtf/Noncopyable.h>
+#include <wtf/PageReservation.h>
#include <wtf/VMTags.h>
-#if HAVE(MMAP)
-#include <errno.h>
-#include <sys/mman.h>
-#endif
-
namespace JSC {
/*
@@ -109,9 +105,9 @@ namespace JSC {
enum { ProgramCodeThisRegister = -CallFrameHeaderSize - 1 };
- static const size_t defaultCapacity = 524288;
- static const size_t defaultMaxGlobals = 8192;
- static const size_t commitSize = 1 << 14;
+ static const size_t defaultCapacity = 512 * 1024;
+ static const size_t defaultMaxGlobals = 8 * 1024;
+ static const size_t commitSize = 16 * 1024;
// Allow 8k of excess registers before we start trying to reap the registerfile
static const ptrdiff_t maxExcessCapacity = 8 * 1024;
@@ -139,81 +135,39 @@ namespace JSC {
void markCallFrames(MarkStack& markStack, Heap* heap) { heap->markConservatively(markStack, m_start, m_end); }
private:
+ void checkAllocatedOkay(bool okay);
+
void releaseExcessCapacity();
size_t m_numGlobals;
const size_t m_maxGlobals;
Register* m_start;
Register* m_end;
Register* m_max;
- Register* m_buffer;
Register* m_maxUsed;
-
-#if HAVE(VIRTUALALLOC)
Register* m_commitEnd;
-#endif
+ PageReservation m_reservation;
WeakGCPtr<JSGlobalObject> m_globalObject; // The global object whose vars are currently stored in the register file.
};
- // FIXME: Add a generic getpagesize() to WTF, then move this function to WTF as well.
- inline bool isPageAligned(size_t size) { return size != 0 && size % (8 * 1024) == 0; }
-
inline RegisterFile::RegisterFile(size_t capacity, size_t maxGlobals)
: m_numGlobals(0)
, m_maxGlobals(maxGlobals)
, m_start(0)
, m_end(0)
, m_max(0)
- , m_buffer(0)
{
- // Verify that our values will play nice with mmap and VirtualAlloc.
- ASSERT(isPageAligned(maxGlobals));
- ASSERT(isPageAligned(capacity));
+ ASSERT(maxGlobals && PageAllocation::isPageAligned(maxGlobals));
+ ASSERT(capacity && PageAllocation::isPageAligned(capacity));
size_t bufferLength = (capacity + maxGlobals) * sizeof(Register);
- #if HAVE(MMAP)
- m_buffer = static_cast<Register*>(mmap(0, bufferLength, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, VM_TAG_FOR_REGISTERFILE_MEMORY, 0));
- if (m_buffer == MAP_FAILED) {
-#if OS(WINCE)
- fprintf(stderr, "Could not allocate register file: %d\n", GetLastError());
-#else
- fprintf(stderr, "Could not allocate register file: %d\n", errno);
-#endif
- CRASH();
- }
- #elif HAVE(VIRTUALALLOC)
- m_buffer = static_cast<Register*>(VirtualAlloc(0, roundUpAllocationSize(bufferLength, commitSize), MEM_RESERVE, PAGE_READWRITE));
- if (!m_buffer) {
-#if OS(WINCE)
- fprintf(stderr, "Could not allocate register file: %d\n", GetLastError());
-#else
- fprintf(stderr, "Could not allocate register file: %d\n", errno);
-#endif
- CRASH();
- }
+ m_reservation = PageReservation::reserve(roundUpAllocationSize(bufferLength, commitSize), PageAllocation::JSVMStackPages);
+ void* base = m_reservation.base();
+ checkAllocatedOkay(base);
size_t committedSize = roundUpAllocationSize(maxGlobals * sizeof(Register), commitSize);
- void* commitCheck = VirtualAlloc(m_buffer, committedSize, MEM_COMMIT, PAGE_READWRITE);
- if (commitCheck != m_buffer) {
-#if OS(WINCE)
- fprintf(stderr, "Could not allocate register file: %d\n", GetLastError());
-#else
- fprintf(stderr, "Could not allocate register file: %d\n", errno);
-#endif
- CRASH();
- }
- m_commitEnd = reinterpret_cast<Register*>(reinterpret_cast<char*>(m_buffer) + committedSize);
- #else
- /*
- * If neither MMAP nor VIRTUALALLOC are available - use fastMalloc instead.
- *
- * Please note that this is the fallback case, which is non-optimal.
- * If any possible, the platform should provide for a better memory
- * allocation mechanism that allows for "lazy commit" or dynamic
- * pre-allocation, similar to mmap or VirtualAlloc, to avoid waste of memory.
- */
- m_buffer = static_cast<Register*>(fastMalloc(bufferLength));
- #endif
- m_start = m_buffer + maxGlobals;
+ checkAllocatedOkay(m_reservation.commit(base, committedSize));
+ m_commitEnd = reinterpret_cast<Register*>(reinterpret_cast<char*>(base) + committedSize);
+ m_start = static_cast<Register*>(base) + maxGlobals;
m_end = m_start;
m_maxUsed = m_end;
m_max = m_start + capacity;
@@ -236,20 +190,11 @@ namespace JSC {
if (newEnd > m_max)
return false;
-#if !HAVE(MMAP) && HAVE(VIRTUALALLOC)
if (newEnd > m_commitEnd) {
size_t size = roundUpAllocationSize(reinterpret_cast<char*>(newEnd) - reinterpret_cast<char*>(m_commitEnd), commitSize);
- if (!VirtualAlloc(m_commitEnd, size, MEM_COMMIT, PAGE_READWRITE)) {
-#if OS(WINCE)
- fprintf(stderr, "Could not allocate register file: %d\n", GetLastError());
-#else
- fprintf(stderr, "Could not allocate register file: %d\n", errno);
-#endif
- CRASH();
- }
+ checkAllocatedOkay(m_reservation.commit(m_commitEnd, size));
m_commitEnd = reinterpret_cast<Register*>(reinterpret_cast<char*>(m_commitEnd) + size);
}
-#endif
if (newEnd > m_maxUsed)
m_maxUsed = newEnd;
@@ -258,6 +203,16 @@ namespace JSC {
return true;
}
+ inline void RegisterFile::checkAllocatedOkay(bool okay)
+ {
+ if (!okay) {
+#ifndef NDEBUG
+ fprintf(stderr, "Could not allocate register file: %d\n", PageReservation::lastError());
+#endif
+ CRASH();
+ }
+ }
+
} // namespace JSC
#endif // RegisterFile_h
diff --git a/JavaScriptCore/wtf/PageAllocation.cpp b/JavaScriptCore/wtf/PageAllocation.cpp
index 01cfbc1..f3fe997 100644
--- a/JavaScriptCore/wtf/PageAllocation.cpp
+++ b/JavaScriptCore/wtf/PageAllocation.cpp
@@ -32,4 +32,17 @@ namespace WTF {
size_t PageAllocation::s_pageSize = 0;
+#ifndef NDEBUG
+
+int PageAllocation::lastError()
+{
+#if OS(WINCE)
+ return GetLastError();
+#else
+ return errno;
+#endif
+}
+
+#endif
+
}
diff --git a/JavaScriptCore/wtf/PageAllocation.h b/JavaScriptCore/wtf/PageAllocation.h
index 7629620..26d53a5 100644
--- a/JavaScriptCore/wtf/PageAllocation.h
+++ b/JavaScriptCore/wtf/PageAllocation.h
@@ -108,18 +108,15 @@ public:
static PageAllocation allocate(size_t size, Usage usage = UnknownUsage, bool writable = true, bool executable = false)
{
- // size must be a multiple of pageSize.
- ASSERT(!(size & (pageSize() - 1)));
+ ASSERT(isPageAligned(size));
return systemAllocate(size, usage, writable, executable);
}
#if HAVE(PAGE_ALLOCATE_AT)
static PageAllocation allocateAt(void* address, bool fixed, size_t size, Usage usage = UnknownUsage, bool writable = true, bool executable = false)
{
- // size must be a multiple of pageSize.
- ASSERT(!(size & (pageSize() - 1)));
- // address must be aligned to pageSize.
- ASSERT(!(reinterpret_cast<intptr_t>(address) & (pageSize() - 1)));
+ ASSERT(isPageAligned(address));
+ ASSERT(isPageAligned(size));
return systemAllocateAt(address, fixed, size, usage, writable, executable);
}
#endif
@@ -127,10 +124,8 @@ public:
#if HAVE(PAGE_ALLOCATE_ALIGNED)
static PageAllocation allocateAligned(size_t size, Usage usage = UnknownUsage)
{
- // size must be a multiple of pageSize.
- ASSERT(!(size & (pageSize() - 1)));
- // size must be a power of two.
- ASSERT(!(size & (size - 1)));
+ ASSERT(isPageAligned(size));
+ ASSERT(isPowerOfTwo(size));
return systemAllocateAligned(size, usage);
}
#endif
@@ -143,14 +138,19 @@ public:
static size_t pageSize()
{
- if (!s_pageSize) {
+ if (!s_pageSize)
s_pageSize = systemPageSize();
- // system page size must be a power of two.
- ASSERT(!(s_pageSize & (s_pageSize - 1)));
- }
+ ASSERT(isPowerOfTwo(s_pageSize));
return s_pageSize;
}
+#ifndef NDEBUG
+ static bool isPageAligned(void* address) { return !(reinterpret_cast<intptr_t>(address) & (pageSize() - 1)); }
+ static bool isPageAligned(size_t size) { return !(size & (pageSize() - 1)); }
+ static bool isPowerOfTwo(size_t size) { return !(size & (size - 1)); }
+ static int lastError();
+#endif
+
protected:
#if OS(SYMBIAN)
PageAllocation(void* base, size_t size, RChunk* chunk)
diff --git a/JavaScriptCore/wtf/PageReservation.h b/JavaScriptCore/wtf/PageReservation.h
index f4ecfdd..906b5a4 100644
--- a/JavaScriptCore/wtf/PageReservation.h
+++ b/JavaScriptCore/wtf/PageReservation.h
@@ -72,10 +72,8 @@ public:
bool commit(void* start, size_t size)
{
ASSERT(m_base);
- // size must be a multiple of pageSize.
- ASSERT(!(size & (pageSize() - 1)));
- // address must be aligned to pageSize.
- ASSERT(!(reinterpret_cast<intptr_t>(start) & (pageSize() - 1)));
+ ASSERT(isPageAligned(start));
+ ASSERT(isPageAligned(size));
bool commited = systemCommit(start, size);
#ifndef NDEBUG
@@ -87,10 +85,8 @@ public:
void decommit(void* start, size_t size)
{
ASSERT(m_base);
- // size must be a multiple of pageSize.
- ASSERT(!(size & (pageSize() - 1)));
- // address must be aligned to pageSize.
- ASSERT(!(reinterpret_cast<intptr_t>(start) & (pageSize() - 1)));
+ ASSERT(isPageAligned(start));
+ ASSERT(isPageAligned(size));
#ifndef NDEBUG
m_committed -= size;
@@ -100,18 +96,15 @@ public:
static PageReservation reserve(size_t size, Usage usage = UnknownUsage, bool writable = true, bool executable = false)
{
- // size must be a multiple of pageSize.
- ASSERT(!(size & (pageSize() - 1)));
+ ASSERT(isPageAligned(size));
return systemReserve(size, usage, writable, executable);
}
#if HAVE(PAGE_ALLOCATE_AT)
static PageReservation reserveAt(void* address, bool fixed, size_t size, Usage usage = UnknownUsage, bool writable = true, bool executable = false)
{
- // size must be a multiple of pageSize.
- ASSERT(!(size & (pageSize() - 1)));
- // address must be aligned to pageSize.
- ASSERT(!(reinterpret_cast<intptr_t>(address) & (pageSize() - 1)));
+ ASSERT(isPageAligned(address));
+ ASSERT(isPageAligned(size));
return systemReserveAt(address, fixed, size, usage, writable, executable);
}
#endif
@@ -123,6 +116,10 @@ public:
systemDeallocate(false);
}
+#ifndef NDEBUG
+ using PageAllocation::lastError;
+#endif
+
private:
#if OS(SYMBIAN)
PageReservation(void* base, size_t size, RChunk* chunk)
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list