2011-02-19 Siddharth Mathur <siddharth.mathur@nokia.com>

        Reviewed by Laszlo Gombos.

        [Symbian] OSAllocator implementation for Symbian OS.
        Manages both data and code region requests. V8 and Sunspider tested
        OK with interpreter. Not tested with JSC JIT yet as it has unrelated
        failures. Also no thread safety yet.
        https://bugs.webkit.org/show_bug.cgi?id=51128

        * JavaScriptCore.pri: removed HAL linkage
        * wtf/Bitmap.h:
        (WTF::::findRunOfZeros): find run of zeros in a bitmap. quick n dirty
        * wtf/OSAllocator.h:
        (WTF::OSAllocator::decommitAndRelease): decommit explicitly
        * wtf/OSAllocatorSymbian.cpp: Impl. of OSAllocator interface
        (WTF::allocateCodeChunk): utility for code chunks
        (WTF::deallocateCodeChunk): utility for code chunks
        (WTF::dataAllocatorInstance): getter for data allocator instance
        (WTF::OSAllocator::reserveUncommitted):
        (WTF::OSAllocator::releaseDecommitted):
        (WTF::OSAllocator::commit):
        (WTF::OSAllocator::decommit):
        (WTF::OSAllocator::reserveAndCommit):
        (WTF::PageAllocatorSymbian::PageAllocatorSymbian): maps requests
        to one underlying Symbian chunk
        (WTF::PageAllocatorSymbian::~PageAllocatorSymbian):
        (WTF::PageAllocatorSymbian::reserve):
        (WTF::PageAllocatorSymbian::release):
        (WTF::PageAllocatorSymbian::commit):
        (WTF::PageAllocatorSymbian::decommit):
        (WTF::PageAllocatorSymbian::contains):
        * wtf/PageAllocatorSymbian.h: Added.
        (WTF::SymbianChunk::SymbianChunk): wrapper around RChunk
        (WTF::SymbianChunk::~SymbianChunk):
        (WTF::SymbianChunk::contains):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@79126 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent f7bc4bd8
2011-02-19 Siddharth Mathur <siddharth.mathur@nokia.com>
Reviewed by Laszlo Gombos.
[Symbian] OSAllocator implementation for Symbian OS.
Manages both data and code region requests. V8 and Sunspider tested
OK with interpreter. Not tested with JSC JIT yet as it has unrelated
failures. Also no thread safety yet.
https://bugs.webkit.org/show_bug.cgi?id=51128
* JavaScriptCore.pri: removed HAL linkage
* wtf/Bitmap.h:
(WTF::::findRunOfZeros): find run of zeros in a bitmap. quick n dirty
* wtf/OSAllocator.h:
(WTF::OSAllocator::decommitAndRelease): decommit explicitly
* wtf/OSAllocatorSymbian.cpp: Impl. of OSAllocator interface
(WTF::allocateCodeChunk): utility for code chunks
(WTF::deallocateCodeChunk): utility for code chunks
(WTF::dataAllocatorInstance): getter for data allocator instance
(WTF::OSAllocator::reserveUncommitted):
(WTF::OSAllocator::releaseDecommitted):
(WTF::OSAllocator::commit):
(WTF::OSAllocator::decommit):
(WTF::OSAllocator::reserveAndCommit):
(WTF::PageAllocatorSymbian::PageAllocatorSymbian): maps requests
to one underlying Symbian chunk
(WTF::PageAllocatorSymbian::~PageAllocatorSymbian):
(WTF::PageAllocatorSymbian::reserve):
(WTF::PageAllocatorSymbian::release):
(WTF::PageAllocatorSymbian::commit):
(WTF::PageAllocatorSymbian::decommit):
(WTF::PageAllocatorSymbian::contains):
* wtf/PageAllocatorSymbian.h: Added.
(WTF::SymbianChunk::SymbianChunk): wrapper around RChunk
(WTF::SymbianChunk::~SymbianChunk):
(WTF::SymbianChunk::contains):
2011-02-19 Yong Li <yoli@rim.com>
Reviewed by Eric Seidel.
......
......@@ -49,12 +49,6 @@ symbian {
INCLUDEPATH = $$JAVASCRIPTCORE_INCLUDEPATH $$INCLUDEPATH
}
symbian: {
LIBS += -lhal
# For hal.h
INCLUDEPATH *= $$MW_LAYER_SYSTEMINCLUDE
}
win32-*: DEFINES += _HAS_TR1=0
DEFINES += BUILDING_JavaScriptCore BUILDING_WTF
......
......@@ -40,6 +40,7 @@ public:
size_t nextPossiblyUnset(size_t) const;
void clear(size_t);
void clearAll();
int64_t findRunOfZeros(size_t) const;
size_t count(size_t = 0) const;
size_t isEmpty() const;
size_t isFull() const;
......@@ -106,6 +107,26 @@ inline size_t Bitmap<size>::nextPossiblyUnset(size_t start) const
return start + 1;
}
template<size_t size>
inline int64_t Bitmap<size>::findRunOfZeros(size_t runLength) const
{
if (!runLength)
runLength = 1;
for (size_t i = 0; i <= (size - runLength) ; i++) {
bool found = true;
for (size_t j = i; j <= (i + runLength - 1) ; j++) {
if (get(j)) {
found = false;
break;
}
}
if (found)
return i;
}
return -1;
}
template<size_t size>
inline size_t Bitmap<size>::count(size_t start) const
{
......
......@@ -77,9 +77,10 @@ inline void* OSAllocator::reserveAndCommit(size_t reserveSize, size_t commitSize
inline void OSAllocator::decommitAndRelease(void* releaseBase, size_t releaseSize, void* decommitBase, size_t decommitSize)
{
ASSERT(decommitBase >= releaseBase && (static_cast<char*>(decommitBase) + decommitSize) <= (static_cast<char*>(releaseBase) + releaseSize));
#if OS(WINCE)
#if OS(WINCE) || OS(SYMBIAN)
// On most platforms we can actually skip this final decommit; releasing the VM will
// implicitly decommit any physical memory in the region. This is not true on WINCE.
// On Symbian, this makes implementation simpler and better aligned with the RChunk API
decommit(decommitBase, decommitSize);
#else
UNUSED_PARAM(decommitBase);
......
/*
* Copyright (C) 2010 Apple Inc. All rights reserved.
* Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
......@@ -26,31 +27,176 @@
#include "config.h"
#include "OSAllocator.h"
#include <wtf/FastMalloc.h>
#include "PageAllocatorSymbian.h"
namespace WTF {
void* OSAllocator::reserveUncommitted(size_t bytes, Usage, bool, bool)
// Array to store code chunks used by JIT engine(s)
static RPointerArray<SymbianChunk> codeChunksContainer;
// The singleton data allocator (non code)
static PageAllocatorSymbian dataAllocator;
_LIT(KErrorStringInternalConsistency, "OSAllocator:ConsistencyError");
_LIT(KErrorStringChunkCreation, "OSAllocator:ChunkInitError");
_LIT(KErrorStringPageSize, "OSAllocator:WrongPageSize");
// Makes a new code chunk for a JIT engine with everything in committed state
static void* allocateCodeChunk(size_t bytes)
{
RChunk c;
TInt error = c.CreateLocalCode(bytes, bytes);
__ASSERT_ALWAYS(error == KErrNone, User::Panic(KErrorStringChunkCreation, error));
codeChunksContainer.Append(new SymbianChunk(c.Handle()));
return static_cast<void*>(c.Base());
}
// Frees the _entire_ code chunk in which this address resides.
static bool deallocateCodeChunk(void* address)
{
bool found = false;
for (int i = 0; i < codeChunksContainer.Count(); i++) {
SymbianChunk* p = codeChunksContainer[i];
if (p && p->contains(address)) {
codeChunksContainer.Remove(i);
delete p;
found = true;
}
}
return found;
}
// Return the (singleton) object that manages all non-code VM operations
static PageAllocatorSymbian* dataAllocatorInstance()
{
return fastMalloc(bytes);
return &dataAllocator;
}
void* OSAllocator::reserveAndCommit(size_t bytes, Usage, bool, bool)
// Reserve memory and return the base address of the region
void* OSAllocator::reserveUncommitted(size_t reservationSize, Usage usage, bool , bool executable)
{
return fastMalloc(bytes);
void* base = 0;
if (executable)
base = allocateCodeChunk(reservationSize);
else
base = dataAllocatorInstance()->reserve(reservationSize);
return base;
}
void OSAllocator::commit(void*, size_t, bool, bool)
// Inverse operation of reserveUncommitted()
void OSAllocator::releaseDecommitted(void* parkedBase, size_t bytes)
{
if (dataAllocatorInstance()->contains(parkedBase))
dataAllocatorInstance()->release(parkedBase, bytes);
// NOOP for code chunks (JIT) because we released them in decommit()
}
void OSAllocator::decommit(void*, size_t)
// Commit what was previously reserved via reserveUncommitted()
void OSAllocator::commit(void* address, size_t bytes, bool, bool executable)
{
// For code chunks, we commit (early) in reserveUncommitted(), so NOOP
// For data regions, do real work
if (!executable)
dataAllocatorInstance()->commit(address, bytes);
}
void OSAllocator::decommit(void* address, size_t bytes)
{
if (dataAllocatorInstance()->contains(address))
dataAllocatorInstance()->decommit(address, bytes);
else
deallocateCodeChunk(address); // for code chunk, decommit AND release
}
void* OSAllocator::reserveAndCommit(size_t bytes, Usage usage, bool writable, bool executable)
{
void* base = reserveUncommitted(bytes, usage, writable, executable);
commit(base, bytes, writable, executable);
return base;
}
// The PageAllocatorSymbian class helps map OSAllocator calls for reserve/commit/decommit
// to a single large Symbian chunk. Only works with multiples of page size, and as a corollary
// all addresses accepted or returned by it are also page-sized aligned.
// Design notes:
// - We initialize a chunk up-front with a large reservation size
// - The entire reservation reserve is logically divided into pageSized blocks (4K on Symbian)
// - The map maintains 1 bit for each of the 4K-sized region in our address space
// - OSAllocator::reserveUncommitted() requests lead to 1 or more bits being set in map
// to indicate internally reserved state. The VM address corresponding to the first bit is returned.
// - OSAllocator::commit() actually calls RChunk.commit() and commits *all or part* of the region
// reserved via reserveUncommitted() previously.
// - OSAllocator::decommit() calls RChunk.decommit()
// - OSAllocator::releaseDecommitted() unparks all the bits in the map, but trusts that a previously
// call to decommit() would have returned the memory to the OS
PageAllocatorSymbian::PageAllocatorSymbian()
{
__ASSERT_ALWAYS(m_pageSize == WTF::pageSize(), User::Panic(KErrorStringPageSize, m_pageSize));
RChunk chunk;
TInt error = chunk.CreateDisconnectedLocal(0, 0, TInt(largeReservationSize));
__ASSERT_ALWAYS(error == KErrNone, User::Panic(KErrorStringChunkCreation, error));
m_chunk = new SymbianChunk(chunk.Handle()); // takes ownership of chunk
}
PageAllocatorSymbian::~PageAllocatorSymbian()
{
delete m_chunk;
}
// Reserves a region internally in the bitmap
void* PageAllocatorSymbian::reserve(size_t bytes)
{
// Find first available region
const size_t nPages = bytes / m_pageSize;
const int64_t startIdx = m_map.findRunOfZeros(nPages);
// Pseudo OOM
if (startIdx < 0)
return 0;
for (size_t i = startIdx; i < startIdx + nPages ; i++)
m_map.set(i);
return static_cast<void*>( m_chunk->m_base + (TUint)(m_pageSize * startIdx) );
}
// Reverses the effects of a reserve() call
void PageAllocatorSymbian::release(void* address, size_t bytes)
{
const size_t startIdx = (static_cast<char*>(address) - m_chunk->m_base) / m_pageSize;
const size_t nPages = bytes / m_pageSize;
for (size_t i = startIdx; i < startIdx + nPages ; i++)
m_map.clear(i);
}
// Actually commit memory from the OS, after a previous call to reserve()
bool PageAllocatorSymbian::commit(void* address, size_t bytes)
{
// sanity check that bits were previously set
const size_t idx = (static_cast<char*>(address) - m_chunk->m_base) / m_pageSize;
const size_t nPages = bytes / m_pageSize;
__ASSERT_ALWAYS(m_map.get(idx), User::Panic(KErrorStringInternalConsistency, idx));
__ASSERT_ALWAYS(m_map.get(idx+nPages-1), User::Panic(KErrorStringInternalConsistency, idx+nPages-1));
TInt error = m_chunk->Commit(static_cast<char*>(address) - m_chunk->m_base, bytes);
return (error == KErrNone);
}
// Inverse operation of commit(), a release() should follow later
bool PageAllocatorSymbian::decommit(void* address, size_t bytes)
{
TInt error = m_chunk->Decommit(static_cast<char*>(address) - m_chunk->m_base, bytes);
return (error == KErrNone);
}
void OSAllocator::releaseDecommitted(void* address, size_t)
bool PageAllocatorSymbian::contains(const void* address) const
{
fastFree(address);
return m_chunk->contains(address);
}
} // namespace WTF
/*
* Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef PageAllocatorSymbian_h
#define PageAllocatorSymbian_h
#include <e32std.h>
#include <wtf/BitMap.h>
namespace WTF {
size_t pageSize();
// Convenience wrapper around an RChunk
class SymbianChunk : public RChunk {
public:
SymbianChunk(TInt handle)
{
SetHandle(handle);
// prevent kernel calls by caching these
m_base = reinterpret_cast<char*>(Base());
m_maxSize = MaxSize();
}
~SymbianChunk()
{
Decommit(0, m_maxSize);
Close();
}
// checks if address is in chunk's virtual address space
bool contains(const void* address) const
{
return (static_cast<const char*>(address) >= m_base && static_cast<const char*>(address) < (m_base + m_maxSize));
}
char* m_base;
size_t m_maxSize;
};
// Size of the large up-front reservation
#if defined(__WINS__)
// Emulator has limited virtual address space
const size_t largeReservationSize = 96*1024*1024;
#else
// HW has plenty of virtual addresses
const size_t largeReservationSize = 256*1024*1024;
#endif
class PageAllocatorSymbian {
public:
PageAllocatorSymbian();
~PageAllocatorSymbian();
void* reserve(size_t);
void release(void*, size_t);
bool commit(void*, size_t);
bool decommit(void*, size_t);
bool contains(const void*) const;
private:
static const size_t m_pageSize = 4096;
SymbianChunk* m_chunk;
Bitmap<largeReservationSize / m_pageSize> m_map;
};
} // namespace WTF
#endif // PageAllocatorSymbian_h
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment